开发者

Accessing jQuery ui object from Accordion change function

This should be really simple, but I can't seem to figure out what to do. I'm trying to figure out if a clicked on section in a jQuery accordion has a class. If it does, we need to execute a function. So far, I've found that I can examine the content section being acted on using the following in the change function:

console.log(ui.newContent);

Looking at the object in Firebug, I can see there's a 0 index. Clicking on the 0 to expand it in Firebug reveals it has something listed as "get classList" as one of the object properties. However, neither of the following work to access this:

console.log(ui.newContent[0].classList);
c开发者_Python百科onsole.log(ui.newContent[0].classList());

However, I was able to get the object's id via this:

console.log(ui.newContent[0].id);

So, out of curiosity, anyone know how to access the classList, or am I just going to have to use the id as a selector and get the object again so I can use .hasClass on it? Seems like a waste but its a possible workaround. Thanks in advance!


jQuery.hasClass() should work for you. In your handler:

if(ui.newContent.hasClass('foo')) {
   // do something
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜