tags:

views:

116

answers:

2

I have this script that creates a new tab in JQuery. Can you check through code on whether that particular tab has been generated?

Thanks!

        function createTab(name) {
            var tabName = "#fragment-" + name;
            $("#container-1 > ul").tabs("add", tabName, name);
            var newTab = $(tabName).css("display", "block");
            newTab.html("<iframe src='ViewPatient.aspx?pname=" + name + "' width='100%' frameborder='0' scrolling='no' height='300'></iframe>");
        };
+1  A: 
$('element').size() > 0
Robert Harvey
From the documentation of size: This returns the same number as the 'length' property of the jQuery object. However, it is slightly slower, so length should be used instead. - so, $(selector).length is better.
Paolo Bergantino
Paolo, I don't think we should advocate these kind of micro optimizations.
SolutionYogi
BTW, size's method is implemented as a one liner, 'return this.length' so it's same as using .length for all practical purposes.
SolutionYogi
+1  A: 
if($('#elementID').length<1)
{
   //element not exist. do something...
}
else{
...
}
Juliano