How to substitute $this for a DOM element

JayZeeBoy
JayZeeBoy used Ask the Experts™
on
I have a function that uses $this - how can I specify an element of the DOM instead of $this?

$('#mygallery li').click(function(ev) {
						var $item = $(this);
						var $target = $(ev.target);
 
						if ($target.is('a.ui-icon-check')) {
							deleteImage($item);
						} else if ($target.is('a.ui-icon-zoomin')) {
							viewLargerImage($target);
						}
 
						return false;
					});
 
				});

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004

Commented:
It is easy, do not use $(this) and just use this.

Author

Commented:
OK,

But if I wanted to reference:

<ul id="mylist">
<li id="item1">some stuff</li>
</ul>

and use the li with id of "item1" instead of $this, what would be the exact code to use?

$('#item1')

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2004

Commented:
Right. And if you wanted just the DOM element, you could use $('#item1'][0]

Author

Commented:
I'm sorry, I must just be missing something here.

Can you show me in my code example how I would reference that <LI> in the example?

$('#mylist li').click(function(ev) {
                                                var $item = $('#item1');
                                                var $target = $(ev.target);
 
                                                if ($target.is('a.ui-icon-check')) {
                                                        deleteImage($item);
                                                } else if ($target.is('a.ui-icon-zoomin')) {
                                                        viewLargerImage($target);
                                                }
 
                                                return false;
                                        });
 
                                });

Open in new window

Author

Commented:
fabulous! thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial