0

I want to check one html element exist inside another html element using jquery.Parent element have id 'preview' and child element have id 'draggable'.How check child element present inside parent element?Any solution for these issue?

My code is

 if($("#preview").has("#draggable").length)
  {
      alert( "First element contain" );
  }
1

2 Answers 2

4

.has() selector returns boolean value. you don't need to find the length. you can simply use has selector to determine whether it contains element or not:

if($("#preview").has("#draggable"))
{
  alert( "First element contain" );
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use .find() and .length as shown :-

if($("#preview").find("#draggable").length){
   alert( "First element contain" );
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.