jquery - find last child element of image -


i have 16 images on image slider div. have written code dynamicaly add img in different classes. need check if image last 1 add in last class.

i have written code display alert if user clicks on last image .

 if($(this).is('img:last'))         {        alert('last child');         }         else         {             alert("atleast nooooooooooooooo");         } 

this not working . have created fiddle http://jsfiddle.net/edgbh/9/ enter image description here

last-child property working in fiddle in slider not working .please help.

thanks , regards,

you have problems in code:

  • does not include jquery library can choose sidebar in jsfiddle

  • you have redundant closing }) @ end of code.

  • to determine whether element last child or not, can use:

    if($(this).is(':last-child'))  

updated fiddle


Comments