Issue
Is there a way to change the text in the h2 inside a class using css or javascript? I think it is possible through JS but not sure how.
Please note that I cannot change span or give id. Also, I have multiple sections that uses the same div class "twocol-box1 superflex-content-6-12" but only one section with the H2 text "old text".
Here is what I have
<div class="twocol-box1 superflex-content-6-12">
<h2>old text</h2>
Solution
If There is only one div with class twocol-box1 superflex-content-6-12
who has h2 as child
document.querySelector("div.twocol-box1.superflex-content-6-12 h2").innerText = "New Value"
If Not U can use nth-child
document.querySelector("div.twocol-box1.superflex-content-6-12:nth-child(<That Div Position>) h2").innerText = "New Value"
for example if you want select the 2nd div then
document.querySelector("div.twocol-box1.superflex-content-6-12:nth-child(2) h2")
Answered By - Heet Vakharia
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.