Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery Checking to see if element has element

Tags:

jquery

I'm using jquery 1.3 and is trying to duplicate the 1.4 .has functionality.

I need to check if the .page element contains the image, and if it doesn't, append it.

Is it something like:

var imageid = thirdimage;

if ($('#page:has(#'+imageid+')') === undefined) {
   $('#page').append($('#'+imageid));
}

Thanks.

like image 448
Mark Avatar asked May 11 '10 02:05

Mark


2 Answers

if( $('#page').find('#'+imageid).length )
  // I has the image! :P
like image 196
Paul Alexander Avatar answered Sep 22 '22 08:09

Paul Alexander


$('#page').find('#'+imageid).length == 0
like image 33
Manfre Avatar answered Sep 25 '22 08:09

Manfre