JQuery attr() Method Example Code


Using JQuery attr() method, we can able to add the attribute the DOM element. In the below example i have added the href attribute to the existing anchor tag.

Sample Code:

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <title></title>

</head>
<body>
<a>Ranga</a>

    <script type="text/javascript">
        jQuery('a').text('JQueryExampleCode.blogspot.com').attr("href", "http://jqueryexamplecode.blogspot.com");
    </script>
</body>
</html>
 

Output:
JQuery attr() Method Example Code
JQuery attr() Method Example Code


Post a Comment

Complete posts