Sunday 15 June 2014

javascript - jQuery: Get elments with custom attribute that has hidden child, add live hover function -



javascript - jQuery: Get elments with custom attribute that has hidden child, add live hover function -

i wanted elements has specific attribute , has kid of specific type hidden. this, wrote selector:

$("*[custom-attr]:has('span:hidden')")

in add-on this, wanted add together live function on hover. illustration this:

$("*[custom-attr]:has('span:hidden')").live("hover", function() { /* */ });

i thought working properly, since got visual result wanted. however, when using firebug, noticed not perfect. when moving mouse within body, if not hovering elements meeting selection, firebug indicates html elements hovered affected (they appear yellowish in firebug html tab). see attached image:

why , how can avoid it?

i noticed similar selector did not cause same behavior, 1 elements without span child:

$("*[custom-attr]:not(:has('span'))").live("hover", function() { /* */ });

thanks.

try using natural browser selectors , way avoid jquery adding temporary attributes. case, instead of has() can use:

$("[custom-attr]").on("mouseenter", function() { if ( $(this).find('span:hidden').length ) { /* code */ }; });

javascript jquery jquery-selectors

No comments:

Post a Comment