Link to home
Start Free TrialLog in
Avatar of Brad Bansner
Brad Bansner

asked on

variable contains id name, how to select based on variable name

The variable "value" has the name of an ID (build that in line 1). Lines 2 and 3 are attempting to do things to objects with the ID of what the variable contains. But I get an error:

$('#'+value).attr('id').addClass is not a function
var value=$(this).attr('id').replace('dir_', 'day_');
$('#'+value).attr('id').addClass('dayblockhl');
$('#'+value).attr('id').children('.gr_mwc_monthblockarrow').addClass('gr_mwc_monthblockarrowhl');

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jrm213jrm213
jrm213jrm213
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leakim971
@haloexpertsexchange's right (no point please) :
var value=$(this).attr('id').replace('dir_', 'day_');
$('#'+value).addClass('dayblockhl');
$('#'+value).children('.gr_mwc_monthblockarrow').addClass('gr_mwc_monthblockarrowhl');
//$('#'+value).find('.gr_mwc_monthblockarrow').addClass('gr_mwc_monthblockarrowhl');

Open in new window

Avatar of Brad Bansner
Brad Bansner

ASKER

Yes, you were both right... two different ways of saying the same thing. I left that attr('id') in by accident. I am slowly learning how to do this stuff on my own. Thank you!