Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I add a class to a div in HTML using jQuery?

I want to use jQuery to add a class named container-c-ml to my HTML code. I have the following code below:

<div id="container">
<button>This is a button</button>
</div>

I have my HTML doc linked to a JavaScript file and I have jQuery added via the <head> tag of my doc. What should I do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the following jQuery code:

$(document).ready(function() {
  $("#container").addClass("container-c-ml");
});

Good luck with further learning to code!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading