I'm trying to select a div where class= pick1-box
given only the ID of a parent using Coffeescript.
jQuery(document).ready ->
pick1value = $('#vote_pick1_id').val
$("#" + pick1value + " .pick1-box").css('background-color', 'green')
I can verify that pick1value
has received a value from $('#vote_pick1_id').val
...
<li class='nominee clearfix' id='146'>
<div class='candidate'>
<img alt="Enders" height="80" src="/assets/25803sm.jpg" />
Dick Waddington
</div>
<div class='pick-boxes'>
<div class='pick1-box'>
1
</div>
<div class='pick2-box'>
2
</div>
</div>
</li>
...
FWIW: $("#" + pick1value)
doesn't seem to work either.
I'm trying to select a div where class= pick1-box
given only the ID of a parent using Coffeescript.
jQuery(document).ready ->
pick1value = $('#vote_pick1_id').val
$("#" + pick1value + " .pick1-box").css('background-color', 'green')
I can verify that pick1value
has received a value from $('#vote_pick1_id').val
...
<li class='nominee clearfix' id='146'>
<div class='candidate'>
<img alt="Enders" height="80" src="/assets/25803sm.jpg" />
Dick Waddington
</div>
<div class='pick-boxes'>
<div class='pick1-box'>
1
</div>
<div class='pick2-box'>
2
</div>
</div>
</li>
...
FWIW: $("#" + pick1value)
doesn't seem to work either.
-
1
fyi
jQuery(document).ready ->
can be written$ ->
– asawyer Commented Feb 23, 2012 at 16:58 - ID's cannot start with numbers, I would start by fixing that. – Kevin B Commented Feb 23, 2012 at 17:01
-
What value does
pick1value
contain? I don't see anything with anid
attribute that also has apick1-box
class. – SenorAmor Commented Feb 23, 2012 at 17:02
1 Answer
Reset to default 3This...
pick1value = $('#vote_pick1_id').val
should be this...
pick1value = $('#vote_pick1_id').val()
because you're not passing arguments.
Right now you're assigning the function itself to the variable instead of calling it.
Pretty sure your .css()
call could eliminate the ()
though...
$("#" + pick1value + " .pick1-box").css 'background-color', 'green'