0

I am creating these div's dynamically when user adds products to compare.

//code in jquery
var innerdiv='<div id="innerdiv'+value.code+'"'+'>'+value.name+'<img src="'+value.thumbnail+'"/></div>';
$('#compare-pane').append(innerdiv);

How do I check dynamically if the compare pane is empty or it has inner divs?

I have to hide a button if compare-pane is empty.

The inner div id is dynamically generated (e.g innerdiv166104).

How do I check if any inner div exists? I cannot use empty check as there are another elements inside compare-pane too which are required.

I cannot fetch the inner div id's as they will be coming dynamically as per users selection.

Krzysztof Janiszewski
  • 3,763
  • 3
  • 18
  • 38
ADIT
  • 119
  • 1
  • 1
  • 9

1 Answers1

2

You can use the "starts with" selector to see if you have any div elements matching a pattern in the id:

if ($('#compare-pane div[id^="innerdiv"]').length > 0) {
    // inner divs exist
}
David
  • 208,112
  • 36
  • 198
  • 279