how to check whether div exist or not parent div?

101 views Asked by At

can we check whether any div exit in parent div ?

Actually In my current example I am appending the div in parent div like this.

 $('#realTimeContents' ).append("<div style='width:22%; float: left; font-size:18px; line-height:200%;' class= 'RLTLeftDiv' ></div><div style='width:78%; float:left; font-size:18px; line-height:200%;'  class= 'RLTRightDiv'></div>");

so when I print on console

console.log( $('#realTimeContents' ).html());

It will print this.

 <div style="width:22%; float: left; font-size:18px; line-height:200%;" class="RLTLeftDiv"></div><div style="width:78%; float:left; font-size:18px; line-height:200%;" class="RLTRightDiv"></div>

I want to check if it exist in realTimeContents then it will true .if not exit then return false and append the given line.

1

There are 1 answers

0
xdazz On

You could check it by:

if (!$('#realTimeContents').find('.RLTLeftDiv').length) {
  $('#realTimeContents' ).append("<div style='width:22%; float: left; font-size:18px; line-height:200%;' class= 'RLTLeftDiv' ></div><div style='width:78%; float:left; font-size:18px; line-height:200%;'  class= 'RLTRightDiv'></div>");
}