michaelmcgurk michaelmcgurk - 3 months ago 11
HTML Question

Add class to existing HTML via jQuery

I have this HTML:

<div id='gallery-1' class='gallery galleryid-73 gallery-columns-0 gallery-size-thumbnail'>
<div class='gallery-item'>
<span class='gallery-icon landscape'>
<img width="300" height="200" src="http://placehold.it/400x300" class="attachment-thumbnail size-thumbnail" alt="Aurore, Watercolour" aria-describedby="gallery-1-205" />
</span>
</div>


I'd like to add a class alongside
gallery-item
.

How do I do this with jQuery?

Answer

Use jquery addclass method

Select the <div class='gallery-item'> with class selector

$(".gallery-item").addClass("col-md-4")