I would like to add styles to only one开发者_Python百科 <h4>
tag wrapped in a class. For example:
<div class="spotSect">
<h4>sample text 1</h4>
<h4>sample text 2</h4>
<h4>sample text 3</h4>
</div>
How can I accomplish this?
It should generally come down to how reliably you can uniquely identify the target element. Will the target always be the first, second, or third child element in this example?
If so, you can use the nth-child selector to specify which of the parent element's children to target (after selecting the parent with .spotSect
).
If not, you may have to do some kind of workaround to uniquely identify it. You could, for example, loop through each child element with .each()
after selecting the parent element and check them for some known attribute or content or something to uniquely identify the one you want. It's not exactly elegant, though. But, again, it comes down to being able to uniquely identify the target.
精彩评论