Add attribute using jquery
To add attribute on html element using
jquery we use .attr method. This
method has two parameters first is name of attribute and second is value of
attribute.
<input type="button" value="Add Attribute" onclick="AddAttribute()" />
<div id="myDiv" class="myClass">
This is a div
</div>
<script type="text/javascript">
function AddAttribute() {
$("#myDiv").attr("title", "Title added by
jquery");
}
</script>
Comments
Post a Comment