开发者

Jquery .size() problem and self executing closure problem

I am facing a problem with jquery and have a question. Please answer them (I am a newbie to jquery).

Question 1:

In this html structure:

<div id="main">
        <div id="abc" width="78px" value="no vla">xyyyyyyyy</div>
        <div id="ppp" width="78px">zzzzzzzzzzzzzzzzzzzzz</div>
</div>
<script src="jquery.js" type="text/javascript">
</script>

<script type="text/javascript">


$.fn.hilight = function(a) {

  alert($('div').size());
};

alert('before');

$('').hilight(89);

</script>

$('div').size() Output is showing 4. But there are 3 divs here. What i am missing ? I checked in firebug for Div tags and found 3 div there. Please help :-(

Question 2:

How self executing closure works ? I mean, when we write:

(function(A){document.write(A);})(jQuery);

does jQuery object is passed into the function ? if i write "abcd" instead of jQuery then parameter A gets the value "abcd". in this case, second () pass value to first () (function i mean)..............With concept of C/C++ it matches ? there is no开发者_如何学JAVA return here, so i am bit confused.


Regarding yoru second question:

its not so much a self executing closure, but a function declaration and call.

(function(A){document.write(A);})(jQuery);

can be broken down to

var f = function(A){document.write(A);}
f(jQuery);

Same thing.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜