Skip to content

Instantly share code, notes, and snippets.

@avireni
Last active October 5, 2015 21:08
Show Gist options
  • Save avireni/2877304 to your computer and use it in GitHub Desktop.
Save avireni/2877304 to your computer and use it in GitHub Desktop.
HTML Manipulation with jquery
Changing Content of HTML through jQuery
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").html("Change the content with jQuery");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Click me</button>
</body>
</html>
Append content to HTML through jQuery
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").append(" <b>Content appended through jQuery</b>.");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Click me</button>
</body>
</html>
Append Content after HTML through jQuery
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").after(" New Paragraph added after HTML");
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>Click me</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment