Reputation:
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
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