8

I wan to retrive all the value of this code using class name. Is it possible in jQuery? I want to retrive only the text within a div or number of div may be change the next 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.example.com">
       **www.zeronebyte.com**
       </a>
       <a target="_blank" href="mailto:[email protected]">
       **[email protected]**
       </a>
       </br>
    </div>
    <div>
     <div>
      <div>
        **+91-9166769666** | 
        <a target="_blank" href="**mailto:[email protected]**"></a>
      </div>
     </div>
    </div>
   </font>
  </span>
5
  • 1
    Question is not clear. rephrasing needed.! Commented Feb 25, 2014 at 4:46
  • 1
    what is the desired output? Commented Feb 25, 2014 at 4:46
  • an array with all text Commented Feb 25, 2014 at 4:47
  • please clarify your question properly... Commented Feb 25, 2014 at 4:54
  • Starting with valid HTML would help. A div can't be inside a span element or font elemet. The font element was deprecated in HTML 4 (15 years ago) and is removed from HTML 5. Browsers will correct these errors, but probably differently so the results you get from whatever script you run in this document will likely be different in different browsers. Commented Feb 25, 2014 at 5:04

3 Answers 3

27

If you get the the text inside the element use

Text()

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

In your code:

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

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

html()

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

In your code:

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

Hope it helps:)

Sign up to request clarification or add additional context in comments.

1 Comment

what happens when it found multiple class with the same name?
3

Try this:

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

DEMO

Comments

3

Without jQuery:

textContent:

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

Markup:

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

Markup including the matched element:

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

though outerHTML may not be supported by all browsers of interest and document.querySelector requires IE 8 or higher.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.