user1542984
user1542984

Reputation:

how to check whether div exist or not parent div?

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.

Upvotes: 0

Views: 99

Answers (1)

xdazz
xdazz

Reputation: 160833

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>");
}

Upvotes: 2

Related Questions