'Give span inside p tag a class in JQuery
I am trying to modify the DOM of some code on a number of pages, in two instances:
<p class="styles_label__gDrbZ"><span><a href="/austin">Home</a></span><span>Review</span></p>
<p class="styles_label__gJ3_z"><span><a href="/new-york">NYC</a></span><span>Guide</span></p>
I need to add a class of category to second span - so eg.
<p class="styles_label__gJ3_z"><span><a href="/new-york">NYC</a></span><span class="category">Guide</span></p>
I can't seem to find a way to do this...
Solution 1:[1]
Try this
$('p').children('span').last().addClass('category')
i hope it was useful !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
