0

I have this JS set up but the tabs are only on one page. So I'd like to only run the function on that page to prevent any undefined is not a function console errors. How can I include a conditional if statement to this?

$(function() {
    $( "#tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
});

So, something like:

if is X page {

    $(function() {
        $( "#tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
    });

}
J82
  • 8,267
  • 23
  • 58
  • 87
  • http://stackoverflow.com/questions/4178578/how-to-get-url-from-browser-adress-bar -or- http://stackoverflow.com/questions/1034621/get-current-url-in-web-browser – ryanlutgen Dec 06 '14 at 03:11
  • `if (typeof obj.foo != 'undefined') { // .. }` which is the same as the ` isset() ' function in PHP. – Kris Dec 06 '14 at 03:11

1 Answers1

2

If that page has a specific class assigned to it, or an element that only applies to that page, you can do it. It would look something like this:

$(function() {
     if ($('body').hasClass('className')) {
          $('#tabs').tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
     }
});
Nate
  • 1,330
  • 1
  • 13
  • 23