How to set content and value in html page using jquery?

How to set content and value in html page?

File name : index.php

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#txt1").text("Hello Sana!");
});
$("#btn2").click(function(){
$("#txt2").html("<b>Hello Mahira!</b>");
});
$("#btn3").click(function(){
$("#txt3").val("Sana Mahtab");
});
});
</script>
</head>
<body>

<p id="txt1">set text here.</p>
<p id="txt2">set html content.</p>

<p>Input field: <input type="text" id="txt3" value="Sana Mahtab"></p>

<button id="btn1">Set Text</button>
<button id="btn2">Set HTML</button>
<button id="btn3">Set Value</button>

</body>
</html>





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here