Home > Blockchain >  Extract data from Dom using jquery
Extract data from Dom using jquery

Time:12-31

I have the following Dom from which I need to extract some data.More precisely I need to extract the time (1:25 am & 5.25 am) using jquery. Is it even possible to do it on such a complicated dom??

<div style="background-size: cover;"><div style="background-size: cover;"><div  style="background-size: cover;">1:25am</div><div  style="background-size: cover;">-</div><div  style="background-size: cover;">4:00am</div></div></div>

CodePudding user response:

console.log($(".hc-inline-block").first().text())
console.log($(".hc-inline-block").last().text())
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div style="background-size: cover;">
  <div style="background-size: cover;">
    <div  style="background-size: cover;">1:25am</div>
    <div  style="background-size: cover;">-</div>
    <div  style="background-size: cover;">4:00am</div>
  </div>
</div>

CodePudding user response:

The DOM in the question is malformed. Opening and closing tags do not match up.

Notwithstanding this, if you give your div an Id then you can use:

Html

<div id="timeDiv"> 
  1:25am
</div>

Script

var content = $("#timeDiv").html();

This will return the html values (e.g. "1:25am") from the div.

  • Related