Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use $(this) with other selector?

For ex.:

$("#"+$(this).attr("id")+" option[value='0']")

Can we reduce the code to something like

$(this+" option[value='0']") 
like image 755
thReality Avatar asked May 26 '11 07:05

thReality


1 Answers

These will do the same as your first statement: find the option elements having 0 as their value and being the (not restrictively direct) child of this.

$(this).find('option[value="0"]')

or

$('option[value="0"]', this)

Resources:

  • jQuery .find()
  • Understanding context in jQuery
  • jsFiddle Illustration
like image 64
kapa Avatar answered Sep 29 '22 00:09

kapa