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>
To select a specific HTML class using JavaScript, we need to target it and then store it as a variable. Here is the one line of JavaScript we need to target this element and store it as a variable: Code from a text editor: const vanillaDescription = document. querySelector('.
In jQuery, the class and ID selectors are the same as in CSS. If you want to select elements with a certain class, use a dot ( . ) and the class name. If you want to select elements with a certain ID, use the hash symbol ( # ) and the ID name.
jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
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:)
Try this:
$(document).ready(function(){
var yourArray = [];
$("span.HOEnZb").find("div").each(function(){
if(($.trim($(this).text()).length>0)){
yourArray.push($(this).text());
}
});
});
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With