below is the structure of my HTML, generated within D365 Portal, how to store the info of div after the paragraph tab of id = "b"
<div class="hidden">
<p id="a">66 message</p>
<p id="b"></p>
<div data-wrapper="true" style="font-family:'Segoe UI','Helvetica Neue',sans-serif; font- size:9pt">
<div>test</div>
</div>
<p></p>
<p id="c">66666</p>
</div>
I’m looking to store the test value into a variable or within the id value of b
Trying to get the value of "test" into a variable
2
Answers
You can use querySelector to target the paragraph with the
b
id.Then use nextElementSibling to get the
div
right after and finally innerText to get the expected information.Optionnally, It may be a good idea to use trim to remove any spaces before or after that text.
I am wondering why you did not add an
id
to thediv
itself.But then we can get the
b
id with id selector