Jquery Add Element

Google Advertisements

Prev Tutorial Next Tutorial

Add Element

tutorial4us

Jquery have some predefined methods to add new elements or contents. It have following methods that are used to add new content;

  • append()
  • prepend()
  • after()
  • before()

append() method

This method are used to inserts content at the end of the selected elements

Example of append()

<!DOCTYPE html>
<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").append(" <b>Appended text</b>.");
    });
});
</script>
</head>
<body>

<p>This is my first program.</p>

<button>Append Text</button>

</body>
</html>

Output

This is my first program.

prepend() method

This method are used to inserts content at the beginning of the selected elements.

Example of prepend()

<!DOCTYPE html>
<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").prepend(" <b>Appended text</b>.");
    });
});
</script>
</head>
<body>

<p>This is my first program.</p>

<button>Append Text</button>

</body>
</html>

Output

This is my first program.

before() method

This method are used to inserts content before the selected elements.

Example of before()

<!DOCTYPE html>
<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").before(" <b>Text Add Before</b>.");
    });
});
</script>
</head>
<body>

<p>This is my first program.</p>

<button>Insert Text</button>

</body>
</html>

Output

This is my first program.

after() method

This method are used to inserts content after the selected elements.

Example of after()

<!DOCTYPE html>
<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").after(" <b>Text Add After</b>.");
    });
});
</script>
</head>
<body>


<p>This is my first program.</p>

<button>Insert Text</button>

</body>
</html>

Output

This is my first program.


Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$50 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Cloud computing is the on demand availability of computer system resources, especially data storage and computing power, without direct active management by the user. Cloud Computing Tutorial

College Projects Related to Java, AWT, C Projects for College, C++ Projects for College, Android Projects. Download Java C C++ Projects

Download Projects

Adsense Advertisements


Buy This ads Space 8076671483

Buy This Ad Space @$120 per Month, Ad Size 300X600 Contact on: hitesh.xc@gmail.com or 8076671483 Try this Keyword C++ Programs