Sorry if the question is worded weird but here is what I'm trying to do. I have to gather a specific line of info from a webpage. What I am having trouble with is I can not figure out the right selector to use, eq()
is not working . Here is the source from the page I'm trying to get the info from.
<div class="info" id="Data">
Domain Name: example.com
<br>
Registry: 12345
<br>
When I inspect element I get div#Data.info (text) I have tried $('div#info.Data').eq(1).text()
and a few other combinations. I an new to scripting and the (text) part is what is I think is throwing me off.
Let's look at your jQuery:
$('div#info.Data') // Gets <div> with id="info" and class="Data"
// ^ You have id and class reversed!
.eq(1) // This gets the 2nd element in the array
// ^ You only tried to get 1 element. What is the 2nd?
.text() // Returns combined text of selected elements
Also there's another issue. Your text is not in its own element. In order to get the textnodes in your current element, you could call .contents()
. jQuery does not treat text nodes like regular elements, though, so I would be careful doing any additional operations on them.
You can retrieve the text like such:
$("#Data").contents().eq(0).text() // -> 'Domain Name: example.com'
$("#Data").contents().eq(2).text() // -> 'Registry: 12345'
Fiddle
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