Home Html How to add and get div tag attributes with jquery?

How to add and get div tag attributes with jquery?

by therichpost
0 comment
jquery

Hello, welcome to therichpost.com. In this post, I will tell you How to add and get div tag attributes with jquery? I personally like jquery very much. Most of my code is full with jquery. When I stuck in php or other language then that stuckness I remove with jquery code.

we all use div tags in html code. Some time we need to add class and id’s to div tag dynamically with jquery.

Here you can check the working code to add and get the div tag attributes like class and id’s with jquery:

Here is the div html code:

<div class=”div” id=”divc”></div>

Here is the working script to get div class and id:

//get class name
$(“#divc”).attr(“class”)

//get id name
$(“.div”).attr(“id”)

Here is the working script to add div class and id:

//add class name
$(“#divc”).attr(“class”, “div2”)

//add id name(remember you can add only id to div)
$(“.div”).attr(“id”, “divc”)

There are so many jquery code, tricks and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.