jQuery this selector function and limitations

0 votes

I need help understanding $(this). Is it possible to narrow the focus of "this" within the parentheses or does "this" preclude the use of any other attributes?

For example: I don't understand why this code:

$(this).children("div")

can't be rewritten like this:

$(this + " div")

without having to resort to something like:

$('#'+$(this).attr("id")+ " div")

Also, can you point me to 'this' in the jQuery documentation? It is difficult to use 'this' as a search term for obvious reasons.

Jun 23 in Web Development by gaurav
• 17,760 points
14 views

1 answer to this question.

0 votes

this isn't a jQuery "thing", but a basic JavaScript one. It can't be re-written the way you have in examples because it's an object, in particular either a DOM element or a jQuery object (depending on what context you're in). So if you did this:

 $(this + " div")

What you'd really be doing is calling .toString() on this to concatenate the strings, resulting in:

 $("[object Object] div")

....which isn't a valid selector.

answered Jun 23 by rajatha
• 7,040 points

Related Questions In Web Development

0 votes
0 answers

jQuery $(this).closest show & hide

I've got a table with multiple rows. ...READ MORE

6 days ago in Web Development by gaurav
• 17,760 points
5 views
0 votes
0 answers

TypeError: this.client.incrementMaxListeners is not a function

I'm making a command for my discord ...READ MORE

Dec 29, 2020 in Web Development by anonymous
• 120 points
323 views
0 votes
1 answer

Jquery and Menu and logo

Seems your anchor tag is not visible ...READ MORE

answered Jun 22 in Web Development by rajatha
• 7,040 points
14 views
0 votes
1 answer

How do I select a sibling element using jQuery?

Use jQuery . siblings() to select the matching ...READ MORE

answered Jun 6 in JQuery by Edureka
• 13,640 points
34 views
0 votes
1 answer

How do I select a sibling element using jQuery?

jQuery siblings() Method The siblings() method returns all ...READ MORE

answered Jun 7 in JQuery by Edureka
• 13,640 points
102 views
0 votes
0 answers

jquery attribute selector escape doublequote

I want to select a html element ...READ MORE

Aug 11 in Web Development by gaurav
• 17,760 points
7 views
0 votes
1 answer

How to use jquery with asp.net ajax?

If you weren't aware, Microsoft is planning ...READ MORE

answered Oct 15, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
190 views
0 votes
1 answer
0 votes
1 answer

$("#select option:second").val() jquery - keep select second value of select box option

Yes, you want the special jQuery eq() selector. ...READ MORE

answered Jun 22 in Web Development by rajatha
• 7,040 points
7 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP