HtmlJquery

How to add and get div tag attributes with jquery?

add and get div tag attributes with jquery

Views

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

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

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

Positive SSL