Get & Set Content and Attributes

Get & Set Content and Attributes

A. Get Attributes

$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});

$("button").click(function(){
alert($("#w3s").attr("href"));
});

 

B. Set Attributes

$("#btn1").click(function(){
$("#test1").text("Hello world!");
});
$("#btn2").click(function(){
$("#test2").html("<b>Hello world!</b>");
});
$("#btn3").click(function(){
$("#test3").val("Dolly Duck");
});

$("button").click(function(){
$("#w3s").attr("href""https://www.w3schools.com/jquery/");
});

Leave a Reply