-2

I have this code below, it also has image URL and many more which I didn't post buti want to get the whole exact div tag exactly it is trimming all the other div tags. like i want "col-sm-8" div tag exact it is from the whole function

<html><body><div class='col-sm-8'>
<div class='MainMessageFormat FixedMarginForMessage'>
<pre><p>test message</p></pre>
</div></div>
<div class='col'>
<div class='MainMessageFormat'>
<pre><p>test message</p></pre>
</div></div>
<div class='row'>
<div class='MainMessage'>
<pre><p>test message</p></pre>
</div></div>
</body></html>
vikas
  • 1
  • 2
  • 1
    Possible duplicate of [How to get element by innerText](https://stackoverflow.com/questions/3813294/how-to-get-element-by-innertext) – hs-dev2 MR Jul 11 '19 at 09:02
  • `var message = document.querySelector('.MainMessageFormat.FixedMarginForMessage pre p').textContent;` – Mamun Jul 11 '19 at 09:08

1 Answers1

1

You can use innerText property of javascript like below:

console.log(document.querySelector('.MainMessageFormat.FixedMarginForMessage').innerText);
<html><body><div class='col-sm-8'>
<div class='MainMessageFormat FixedMarginForMessage'>
<pre><p>test message</p></pre>
</div></div>
</body></html>
Shivani Sonagara
  • 1,299
  • 9
  • 21
  • working but can you help me with one more part.... if it has 2 or more div tags like

    test message

    test message

    from this i need the whole first div tag with everything inside it... with
    to
    considering there are many more div tags
    – vikas Jul 11 '19 at 09:17
  • i.e. with the same class name like MainMessageFormat FixedMarginForMessage? – Shivani Sonagara Jul 11 '19 at 09:18