javascript - jQuery issue with child elements -


i don't understand why last part of code affects second div , not first first bit does. in addition, of other content there disappears, not desired behavior. book reading doesn't explain why second div affected , not first. why happening second , not first?. assumed div:last-child alter first div it's considered immediate parent?.

jquery

$(document).ready(function(){   $('div:first-child').text('this first child');      $('div:last-child').text('i\'ve changed this!');  }); 

html

<div id=”myfirstdiv”>   <strong class=”changemytext”>some name</strong>   <p class=”changemytext”>some text<p>   <strong>another name</strong>   <p>more text<p> </div>  <div id=”myseconddiv”>   <strong class=”changemytext”>some name</strong>   <p class=”changemytext”>some text<p>   <strong>another name</strong>   <p>more text<p> </div> </body> 

first-child causes hit first option available, last-child causes hit last 1 (the second in case. if didn't add pseudo selector, both hit both of them.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -