user1730332 user1730332 - 1 year ago 69
Javascript Question

Not able to figure out how to use children and first function jquery

I am trying to write a scrape function from in which I am trying to get the word and it's pronunciation.
I have this div that i need to fetch the data from but I am unable to, not sure what I am doing wrong. I am fetching other div's data(which is a word) just fine but this particular div(pronunciation ) New to jquery, node.js. Anything in the right direction would be great.

this is what I have tried which is working on other div just fine.(to get the 'word' from a div working fine but when i come to get the pronunciation it doesn't work)

$('.header-row-header-extras-pronounce-pronset').filter(function() {
var data = $(this);
pronunciation += data.children().first().text();

console.log("prp: " + pronunciation);
json.pronunciation = pronunciation;

<div class="header-row header-extras pronounce pronset">
<span class="pron spellpron" style="display: inline;">[<span class="dbox-bold">ak</span>-tiv]</span>
<span class="pron ipapron" style="display: none;">/ˈæk tɪv/ </span>
<span class="pre-def-data"> </span>
<button class="prontoggle pronounce-button pronounce-Spell-button">Spell</button>
<button class="syllable-button syllable-button-off" data-header="1">Syllables</button>

Tom Tom
Answer Source

Your selector is selecting one long class, where the mark-up has separate classes.

For the mark-up:

<div class="header-row header-extras pronounce pronset">

Use this selector:


Select elements in jQuery just as you would select them with CSS.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download