开发者

If else statment with tab i'm on now Jquery

Hello everybody I'm working on Jquery tabs, I have a tab which is a class function addClass and remove content

I have an IF ELSE made ​​and looks like

$ (function () {
  if (ui.panel.id == 'tab-1') {
    $ ("#DIV_ID").addClass ("CLASS", 0);
开发者_开发百科    return false;
  } else {
    $ ("#DIV_ID").removeClass ("CLASS", 0);
    return false;
  }
});

Is this a way to look on with tab he is? If not how should I do?

[EDIT]

Mine code http://jsfiddle.net/Csq6x/12/


Javascript is case-sensitive, so AddClass and addClass are different things. Although excess whitespace is ignored, it's not allowed to put them in identifiers. Also, the addClass and removeClass methods accept only one argument. Furthermore, # DIV_ID would probably not work because it would match an empty ID (which would not be possible) with a descendant node having tagname "DIV_ID". You need to change that to #DIV_ID:

$ (function () {
  if (ui.panel.id == 'tab-1') {
    $ ("#DIV_ID"). addClass ("CLASS");
    return false;
  } else {
    $ ("#DIV_ID"). removeClass ("CLASS");
    return false;
  }
});

Also, I don't know where you've put this snippet, but note that this code is executed once the document is ready. So if it's within <script> tags, it's executed and not when switching tabs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜