user1730332 user1730332 - 3 months ago 11
Javascript Question

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

I am trying to write a scrape function from dictionary.com 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 )...no. 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">
<div>
<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>
</div>
<div>
<button class="prontoggle pronounce-button pronounce-Spell-button">Spell</button>
<button class="syllable-button syllable-button-off" data-header="1">Syllables</button>
</div>
</div>



Tom Tom
Answer

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:

$('.header-row.header-extras.pronounce.pronset').

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