开发者

What is .previous method and is it jQuery or core JS or some other library?

I have encountered this solution for a problem I tried to solve (uncheck radio buttons), which works perfectly, but I can't find anywhere on google what does .previous do and is it JS core or some library?

$('input[type=radio]').click(function(){
    if (this.previous) {
        this.checked = false;
    }
    this.previous = this.checked;
});

this is t开发者_开发百科he original question


What you've quoted isn't anything I'm familiar with. The prev method is jQuery-specific. It gives you the previous sibling element. The DOM equivalent property is previousSibling (which may not be an Element, it may be a text node or something else).

It looks there like someone's creating an expando property on the element. I would strongly recommend against an expando property called previous, but there you go.


You can add any variable to an existing object, in this case the input type radio gets another property called previous. Its part of the core javascript.


if ($(this).prev()) { ...

You could try use the above. http://api.jquery.com/prev/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜