Friday, 12 August 2016

ADD ELEMENT TO AN HTML PAGE WITHOUT RELOADING THE PAGE(USING JQUERY)

there are several way to add add an element to an html page without loading a new page the best way is to use the jquery library. below is a sample code of a simple way to add a new content to an html page

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>

$(document).ready(function(){
       $("#btn2").click(function(){
        $("ol").append("<li>Appended item</li>");
    });
});
</script>
</head>
<body>
<ol>
  <li> item 1</li>
  <li> item 2</li>
  <li> item 3</li>
</ol>
<button id="btn2">Append list items</button>
</body>
</html>

how it works:

1.first you can either use an online library for your jquery as i did or you can download an offline version of the library.
note: a jquery function will not have effect except you have the library.

2. write you jquery code or function: the inbuilt jquery function for this is called append
$("p").append("Some appended text.");  append add text or element at the end of a page or a tag
note jquery also has a function for adding text or element to the beginning of your post
this is called prepend $("p").prepend("Some prepended text.");
$(document).ready(function(){
    $("#btn2").click(function(){
        $("ol").append("<li>Appended item</li>");
    });
});
above is the jquery of the page first we create a button with a unique id in this case  btn2 this calls the function append of the element ol.

3. create your list items.

click here  for what you should have if you are correct



Share:

1 comment:

  1. Add Element To An Html Page Without Reloading The Page(Using Jquery) ~ Itgist >>>>> Download Now

    >>>>> Download Full

    Add Element To An Html Page Without Reloading The Page(Using Jquery) ~ Itgist >>>>> Download LINK

    >>>>> Download Now

    Add Element To An Html Page Without Reloading The Page(Using Jquery) ~ Itgist >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete