开发者

jQuery call on a <div> tag (or any HTML element) - is looping implied?

I'm learning jQuery and had a question about a method call on an HTML element. In this case it's a <div> tag.

The jQuery call goes like this:

<script type="text/javascript">

$(function(){
 $('.someClass').myMethod({
  value1: 'sometext',
  value2: 'someothertext'
  });
 });

</script>

The <div> tag has a CSS class of 'someClass', as you can see below:

<div class="so开发者_开发技巧meClass" style="display: none;">
<div id="my-content">
<img id="enter" alt="Logo" src="images/logo.png">
</div>
</div>

My question is, what's happening with that method call in jQuery? Is it looping over all elements contained within the <div class='someClass'/> and calling myMethod on all of them?


Your method call isn't looping over the contents of your div. It's looping over all elements with the class someclass. The "cascading" part of CSS will, however, apply the styles to all contained elements of your div.


It completely depends on the plugin implementation.

$('.someClass') will select all the elements with calss .someClass now its the plugin which will use this set and apply its logic on the set of matched elements or just a single element.


Nope, it will call a jQuery method "myMethod" (which does not exist unless you wrote a plugin that implements it) on all elements matched, that is all elements having a CSS class "someClass".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜