开发者

Jquery object compare problem

How to compare two Jquery object?

$('<p></p>')[0] === $('<p></p>')[0]
false

$('<p></p>') == $('<p></p>')
false

$('<p></p>').get() == $('<p></p>').get()
fal开发者_运维问答se


The following returns true

$('<p></p>').html() == $('<p></p>').html();

Is that what you need?

Edit: The old jQuery group^ discussion on this suggests comparing the child nodes in plain JavaScript since each jQuery object is an array of references to DOM objects. This function was also the accepted answer on this SO question.

^Tried the new jQuery forum but it has not imported the discussion correctly.


$('<p>') // it creates a new dom element. 
         //Equivalent to document.createElement('p')

so the two

$('<p></p>')[0] and $('<p></p>')[0]

are in fact two distinct DOM elements.


$('<p></p>')[0].outerHTML === $('<p></p>')[0].outerHTML;   // true
$('<p>hi</p>')[0].outerHTML === $('<p></p>')[0].outerHTML; // false


I found a stupid solution ... anyone got better one?

$.md5($('<p></p>').get()[0].toString()) ==$.md5($('<p></p>').get()[0].toString())

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜