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

Popular posts from this blog

Using Progress Bar In C#

Get elements by class name in javascript

Jquery serer side datatables in asp.net