Categories

Tuesday, December 3, 2024
#919814419350 therichposts@gmail.com
HtmlJquery

How to add and get div tag attributes with jquery?

add and get div tag attributes with 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

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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