Get and Set HTML attributes in jquery

<input type="button" id="get_attribute" value="Get Attribute">
<input type="button" id="set_attribute" value="Set Attribute">
<input type="button" id="set_multiple_attribute" value="Set Multiple Attribute">
<a href="http://www.coding4developers.com/" target="_blank">Coding 4 Developers </a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$('#get_attribute').click(function(){
var link = $('a').attr('href');
alert(link);
});

$('#set_attribute').click(function(){
$('a').attr('href','http://www.coding4developers.com/jquery/get-and-set-html-attributes-in-jquery/');
});

$('#set_multiple_attribute').click(function(){
$('a').attr({
"href" : "http://www.coding4developers.com/jquery/get-and-set-html-attributes-in-jquery/",
"title" : "Coding 4 Developers"
});
});
</script>

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *