Skip to main content
added 99 characters in body
Source Link
cicakman
  • 2k
  • 5
  • 22
  • 34

I have this code which is not working jQuery

if($("#dis(h3)").length == 0) $("#dis").append("<p>no display</p>"); 

HTML:

<div id="dis"> <h3>Title</h3> //append here </div> 

The append code should work

<div id="dis"> <h3>Title</h3> <p>Text</p> </div> 

The append code should not work.

Edit: I need the append code to appear if there is no other element inside #dis beside h3

What should i do to make it as above(intended)

I have this code which is not working jQuery

if($("#dis(h3)").length == 0) $("#dis").append("<p>no display</p>"); 

HTML:

<div id="dis"> <h3>Title</h3> //append here </div> 

The append code should work

<div id="dis"> <h3>Title</h3> <p>Text</p> </div> 

The append code should not work.

What should i do to make it as above(intended)

I have this code which is not working jQuery

if($("#dis(h3)").length == 0) $("#dis").append("<p>no display</p>"); 

HTML:

<div id="dis"> <h3>Title</h3> //append here </div> 

The append code should work

<div id="dis"> <h3>Title</h3> <p>Text</p> </div> 

The append code should not work.

Edit: I need the append code to appear if there is no other element inside #dis beside h3

What should i do to make it as above(intended)

Source Link
cicakman
  • 2k
  • 5
  • 22
  • 34

jQuery check if ANY element exists

I have this code which is not working jQuery

if($("#dis(h3)").length == 0) $("#dis").append("<p>no display</p>"); 

HTML:

<div id="dis"> <h3>Title</h3> //append here </div> 

The append code should work

<div id="dis"> <h3>Title</h3> <p>Text</p> </div> 

The append code should not work.

What should i do to make it as above(intended)