X
Publisher: Sigit purnomo kangsigit.com@gmail.com

How to Use the attr Using JavaScript

Very simple, but more simple if you use jQuery. Before I started to the subject, you should know the differences in the application of attr if using JavaScript and jQuery

Remove CLASS attribute with javascript
document.getElementById("nameID").removeAttribute("class")

Remove CLASS attribute with jQuery
$("#nameID").removeAttr("class");

Add  CLASS attribute with javascript
document.getElementById("nameID").setAttribute("class", "newClass")

Add CLASS attribute with jQuery
$("#nameID").attr("class", "newClass");

Advertisement


Examples Removes attribute ID with JavaScript
<div id="ex" style="font-weight:bold">Hello world!</div>
<button onclick="test()">TEST THIS CODE</button>

<script>
function test(){
document.getElementById("ex").removeAttribute("id")
}
</script>

<style>
#ex {color:red}
</style>
Test your code here
Advertisement

no image
Add Comments
0 Comments
Click Here to Add Comments

No Comment