business logic - jQuery end(), where exactly it is useful -
i have looked in jquery documentation of function end(),
definition : end recent filtering operation in current chain , return set of matched elements previous state.
i have understood functionality, not able make out, more helpful.
ex:
<p>text</p> <p class="middle">middle <span>text</span></p> <p>text</p> <script type="text/javascript"> alert(jquery('p').filter('.middle').length); //alerts 1 alert(jquery('p').filter('.middle').end().length); //alerts 3 alert(jquery('p').filter('.middle').find('span') </script>
i have understood second line displaying //alerts 3
, can written as
alert(jquery('p').length); //alerts 3
then why 2 methods .filter
, .end()
,
please give me example, .end() useful.
html
<p>text</p> <p class="middle">middle <span>text</span></p> <p>text</p>
in p tag sibling element
and pwith class "middle" has child tag "span" tag
now talk js
<script type="text/javascript"> /*it display 1 , right first find p tag in filter "middle class" , in p tag 1 have class alert 1 */ alert(jquery('p').filter('.middle').length); /*it display 3 , right first find p tag in filter "middle class" again use end inn jquery again goes previous selector means (jquery('p').filter('.middle') jquery('p') alert 3 */ alert(jquery('p').filter('.middle').end().length); //alerts 3 /*it display 3 , right first find p tag in filter "middle class" again use find span , has 1 span in middle class alert 1 */ alert(jquery('p').filter('.middle').find('span').length); alert 1 </script>
reference end
Comments
Post a Comment