Alternative for jQuery's is() function?

若如初见. 提交于 2019-12-11 07:48:23

问题


I was using jQuery's .is() function (the one introduced in 1.6, not the prior version of it) to compare an object, but it unfortunately won't work with jQuery 1.5.2, which is what I am using. I'm wondering if there is some kind of alternative that I can use?

I'm thinking of cloning each object and then comparing it, but this doesn't seem like the best way to do this.

                $('#js-show-more-toggle').contents().each(function() {
                if (seen) {
                    $wrapper.append(this);
                } else if ($(this).is($marker)) {
                    // This is what we want to show
                    seen = true;
                }
            }).end().append($wrapper, $more);

jsfiddle : http://jsfiddle.net/someprimetime/n4jnr/14/


回答1:


You can use this === $marker[0] to compare the two DOM elements.

Consider upgrading to a recent jQuery version though. Except some minor changes it's usually pretty easy.



来源:https://stackoverflow.com/questions/9012774/alternative-for-jquerys-is-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!