Search code examples
jquery-uijquery-ui-tabs

How do I check if a tab exists in jQuery UI?


Currently I use this to check if a tab(element) already exists:

if(!$('#'+element).length){
   //... code to add new tab if not exists.
} else {
   Alert("Tab or portlet already exists...");
}

This is very dirty and I get a "uncaught exception: Syntax error, unrecognized expression: #" from FireBug. If element already exists, the "Alert" doesn't show, I think it hangs at the first exception.

Is there a better way to check if an element exists? (Or a tab)

I am using this for my personal project @ http://www.soliman.nl/test/jqueryui/ui_2.php


Solution

  • The problem seems to be in your source - you are passing "#foo" as the parameter element, then prepending another "#". The result is $("##foo"), which just isn't going to work.