asked on
$('.product-price').contents().eq(2).text()
<div class="product-price">
<span class="price">
<strike>349,00 </strike>
</span>
49,00
<span class="currency">DKK</span>
</div>
When you dump this with console.log($('.product-price').contents());
Gives the following {…}
0: #text "
"
1: <span class="price">
2: #text "
49,00
"
3: <span class="currency">
4: #text "
"
context: HTMLDocument http://mrcp9/ee/t2981.html
length: 5
prevObject: Object { 0: div.product-price, length: 1, selector: ".product-price", … }
__proto__: Object { jquery: "1.11.1", constructor: jQuery(), length: 0, … }
t2981.html:54:2
There is an empty text node linked to the original <div> that increases the index of the target node which is the third (index 2) element.<div class="product-price"> <span class="price"><strike>349,00 </strike></span>49,00 <span class="currency">DKK</span></div>
And the solution breaks.
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY
ASKER