" ... If I create a div inside whatever function thanks gosh Sizzle
won't return
that div in a search $("div"), do you follow me? ..."
I "follow" this yes, I am just "wondering" if this FF "feature" might
break "something somewhere" in jQ,
because jQ users are allowed to create dom nodes "on fly"and use them
as a container (aka context), with Sizzle, without ever attaching them
to the curent dom tree:
// example 1
function faraway ( jq_ ){ return jq_.find(".a") ; }
//
$div = $("<div style='color:red!important' ><div><div><div class='a b
c'>ABC</div></div></div></div>") ;
// now pass and search inside this "un-attached" element
$a = faraway( $div ) ;
//
$a.css("color")
/* returns : red */
And , yes, for the above test
Returns is an empty string (aka "") in CHROME :
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.3
(KHTML, like Gecko) Chrome/4.0.223.11 Safari/532.3
Return is "red" in IE8 :
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0;
SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;
Media Center PC 6.0)
And return is "rgb(255, 0, 0)" (aka "red") in FF :
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.3) Gecko/
20090824 Firefox/3.5.3
This example is not that esoteric jQ usage, and thus it is more likely
to happen. And fail in CHROME ...
Now I do not know is this only this Chrome . is it also the same in
Chromium, or in Opera 10, etc ... ?
For now I attach element to the head (temporarily) which seems to
work.
function example2(color) {
function faraway(jq_) { return jq_.find(".a"); }
var $div = $("<div style='color:" + color + "!important'
><div><div><div class='a b c'>ABC</div></div></div></div>");
// do this for browsers (like CHROME) who do not allow CSS2
properties on non-attached element
$div.appendTo($("head"));
// now pass and search inside this "un-attached" element
var $a = faraway($div);
var retval = $a.css("color")
$div.remove();
return retval;
}
example2("red") returns "red" in IE and "rgb(255,0,0)" in FF and
CHROME ...
AS I said, if jQ team thinks this is necessary to solve before people
start complaining (possibly) about jQ + Chrome, they are wellcome to
use these findings.
--DBJ