problems with selectors on this
I want to use the :first selector on this but something is wrong because the action is done on the html tag.
Example:
- <html>
- <head><script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
- <script type="text/javascript">
- (function($) {
$.fn.myplugin = function() {
- $(this+":first").addClass("firstparent");
- $(this+":last").addClass("lastparent");
- return this.each(function() {
- $(this).children(":first").addClass("firstchild");
- $(this).children(":last").addClass("lastchild");
- });
- }
- })(jQuery);
- </script>
- </head>
- <body>
- <ul>
- <li>1.1</li>
- <li>1.2</li>
- </ul>
- <ul>
- <li>2.1</li>
- <li>2.2</li>
- </ul>
- <script type="text/javascript">jQuery("ul").myplugin();</script>
- </body>
- </html>
It should like this:
- <html>
- [...]
- <body>
- <ul class="firstparent">
- <li class="firstchild">1.1</li>
- <li class="lastchild">1.2</li>
- </ul>
- <ul class="lastparent">
- <li class="firstchild">2.1</li>
- <li class="lastchild">2.2</li>
- </ul>
- <script type="text/javascript">jQuery("ul").myplugin();</script>
- </body>
- </html>
But it looks like this:
- <html class="firstparent">
- [...]
- <body>
- <ul>
- <li class="firstchild">1.1</li>
- <li class="lastchild">1.2</li>
- </ul>
- <ul>
- <li class="firstchild">2.1</li>
- <li class="lastchild">2.2</li>
- </ul>
- <script class="lastparent" type="text/javascript">jQuery("ul").myplugin();</script>
- </body>
- </html>
I have tested a lot of things but can't find the solution on my self.