Loading Please Wait...
jQuery contains powerful methods for changing HTML elements, attributes, and values.
We will use the same three methods from the previous page to set content:
$("#test1").text("Hello world!");
$("#test2").html("This is <b>bold</b> paragraph.");
$("#input").val("Lynxsia IT Solutions");
All of the three jQuery methods above: text(), html(), and val(), also come with a callback function. The callback function has two parameters: the index of the current element in the list of elements selected and the original (old) value. You then return the string you wish to use as the new value from the function.
$("#test1").text(function(i, origText){
return "Old text: " + origText + " New text: Hello world! (index: " + i + ")";
});
The jQuery attr() method is also used to set/change attribute values.
$("#link").attr('href', 'https://lynxsia.com/')
The attr() method also allows you to set multiple attributes at the same time.
$("#w3s").attr({
"href" : "https://www.w3schools.com/jquery/",
"title" : "W3Schools jQuery Tutorial"
});
The jQuery method attr() also comes with a callback function. The callback function has two parameters: the index of the current element in the list of elements selected and the original (old) attribute value. You then return the string you wish to use as the new attribute value from the function.
$("#w3s").attr("href", function(i, origValue){
return origValue + "/jquery/";
});
The data() method is also used to set/change data attribute values.
$("#test").data('user', 'John Doe')
How you feel about this blog:
Share this blog on:
If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com
Contact UsWe are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..
Copyright ©
, Lynxsia IT Solutions, All rights reserved