Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get the info of a div after a Paragraph tag in an hidden DIV

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

const myVariable = document.querySelector('#b').nextElementSibling.innerText.trim()

console.log(myVariable)
.hidden{
  display: none;
}
<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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading