Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use sizzle.js separate

I downloaded sizzle.js from https://github.com/jquery/sizzle my code is:

<!DOCTYPE html>
<html>
<head>
    <title>Demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="sizzle.js" type="text/javascript"></script>
    <script type="text/javascript">
        window.onload=load;
        function load(){
            alert(Sizzle("#test"));
            alert(Sizzle("#test").innerHTML);
        }
    </script>
</head>
<body>
<div id="test">abc</div>
</body>
</html>

but alert "[object]", "undefined", please tell me what's wrong with my code?

like image 577
artwl Avatar asked Feb 20 '12 03:02

artwl


1 Answers

The Sizzle() function returns an array of matched elements. So if you know there'll be exactly one matching element (which there should be if you're selecting by id) try:

alert(Sizzle("#test")[0].innerHTML); 
like image 83
nnnnnn Avatar answered Sep 30 '22 18:09

nnnnnn