xqz
xqz

Reputation: 41

jQuery selector, cant pass through

I have

echo '<div><span>'.$wiersz['data'].'<i> added by: '.$wiersz['username'].'</i></span><span>Rate: </span><i **FROM HERE**>'.$wiersz['likes'].'</i><i>'.$wiersz['unlikes'].'</i></div>';

echo '<div><span>'.$wiersz['data'].'<i> added by: '.$wiersz['username'].'</i></span><span>Rate: <i>Thank you</i></span><i **OVERHERE**>'.$wiersz['likes'].'</i> <i>'.$wiersz['unlikes'].'</i></div>';

How Can I go FROM (FROM HERE) to the (OVER HERE) by selectors in jQuery? I'm hiding first div and showing second div. I need to increase innerText of OVERHERE but I dont know how to go there by selectors.

I did:

$(this).parent().next() 

this lead me to second div but still cant go into OVERHERE in second div.

Upvotes: 1

Views: 32

Answers (2)

mplungjan
mplungjan

Reputation: 177701

Assuming this is how the rendered HTML looks like

<div>
  <span>data<i> added by: username</i></span>
  <span>Rate: </span>
  <i onclick="$(this).closest('div').next().find('i').eq(2).text(parseInt($(this).text(),10))">25 Likes</i>
  <i>unlikes</i>
</div>
<div>
  <span>data<i> added by: username</i></span>
  <span>Rate: <i>Thank you</i></span><i>Will be overwritten </i> <i>unlikes</i>
</div>

Or $(this).parent().next() instead. However closest is safer in case you wrap your <i> in something

Upvotes: 1

jrath
jrath

Reputation: 990

try this..

$(this).parent().next().children()[2]

Upvotes: 2

Related Questions