jQuery Set Content and Attributes


  1. text() – Sets or returns the text content of selected elements
  2. html() – Sets or returns the content of selected elements (including HTML markup)
  3. val() – Sets or returns the value of form fields

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

The jQuery attr() method is also used to set/change attribute values.

$(“button”).click(function(){
$(“#w3s”).attr(“href”, “http://www.w3schools.com/jquery&#8221;);
});

$(“#w3s”).attr({
“href” : “http://www.w3schools.com/jquery&#8221;,
“title” : “W3Schools jQuery Tutorial”
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s