Prev Demo
jQuery
>
.Attr() - Get Set Attribute Value
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <style> #div2{ color: gray; background-color: orange; font-size: 20px; } </style> </head> <body> <div id="div1"> <p class="class">This is CLASS in #div1</p> <p class="class1">This is CLASS1 in #div1</p> <p class="class2">This is CLASS2 in #div1</p> <p class="class3">This is CLASS3 in #div1</p> </div> <hr /> <div id="div2"> <div class="class">This is CLASS attribute in #div2</div> <p class="class1">This is CLASS1 in #div2</p> <div class="class2">This is CLASS2 attribute in #div2</div> <p class="class3">This is CLASS3 in #div2</p> </div> <script> $("#div2").attr('class', 'class2'); alert($("#div2").attr('class')); </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output