Sven OS
Sven OS

Reputation: 35

Check if Grid/Subgrid exists

I want to check if my subgrid exists (is expanded).

I wanna do this because i want to save all my changed data in my grid and all my subgrids with one button. But there isn't always every subgrid expanded (i'll do this in a double-iteration) - so i have to check if the subgrid is there to save it.

I tried

if(jQuery("#example").grid) { ... }

and

if(jQuery("#example")) { ... }

But the output of these statements is always "undefined". The grid-names are definitely right - i just wrote here #example for example ;-)

Thank you!!

Upvotes: 0

Views: 3507

Answers (1)

charlietfl
charlietfl

Reputation: 171690

When you want to find if an element exists test length of the jQuery object

if(jQuery("#example").length) {
   /* element with ID=example exists*/
}

You mention expanded but gave no indication with html sample or explanation how expanded works.

Also note that ID's can't be duplicated in a page. If you have duplicate ID's would definitely need to see html in order to create better solution for traversing. I mention this due to reference of multiple sub grids and an ID selector being used as sample code

Upvotes: 1

Related Questions