How to get value by class name in JavaScript or jquery?

i wan to extract the full value of this code using the class name .. this is possible in jquery. I want to extract only the text in the div or the number of div can change the following form

  <span class="HOEnZb adL">
    <font color="#888888">
    </br>
    <div>
      <i><font color="#3d85c6" style="background-color:#EEE"></i>
    </div>
    <div>
       **ZERONEBYTE Software** |  
       <a target="_blank" href="http://www.zeronebyte.com">
       **www.zeronebyte.com**
       </a>
       <a target="_blank" href="mailto:info@zeronebyte.com">
       **info@zeronebyte.com**
       </a>
       </br>
    </div>
    <div>
     <div>
      <div>
        **+91-9166769666** | 
        <a target="_blank" href="**mailto:deepika.zeronebyte@gmail.com**"></a>
      </div>
     </div>
    </div>
   </font>
  </span>
+3
source share
3 answers

If you get text inside an element, use

Text()

$(".element-classname").text();

In your code:

$('.HOEnZb').text();

if you want to get all the data including html Tags:

html ()

 $(".element-classname").html();

In your code:

$('.HOEnZb').html();

Hope this helps :)

+16
source

Try the following:

$(document).ready(function(){
    var yourArray = [];
    $("span.HOEnZb").find("div").each(function(){
        if(($.trim($(this).text()).length>0)){
         yourArray.push($(this).text());
        }
    });
});

DEMO

+3
source

jQuery:

TextContent:

var text = document.querySelector('.someClassname').textContent;

:

var text = document.querySelector('.someClassname').innerHTML;

, :

var text = document.querySelector('.someClassname').outerHTML;

outerHTML , document.querySelector IE 8 .

+2