need to modify class of child image

My code attached successfully removes two classes whenever they appear on a .dayblockhl element, and adds a class dayblockhl to the element that was clicked.

The 4th thing I'm trying to do is add a class to the image with a class of gr_mwc_monthblock that is a child element of the clicked DIV. I need to select the child IMG within the clicked DIV. The syntax of my code must be off. How can I do this?

Thank you!
$(function(){
	$('.dayblock').click(function(){
		$('.dayblockhl').removeClass('dayblockhl');
		$('.gr_mwc_monthblockarrowhl').removeClass('gr_mwc_monthblockarrowhl');
		$(this).addClass('dayblockhl');
		$(this).addClass('gr_mwc_monthblockarrowhl');
	});
});

<div class="dayblock" id="day_5_8_2011">
	<img class="gr_mwc_monthblockarrow" src="art/gr_mwc_monthblockarrow.png" width="9" height="11" border="0" /> May 8<br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock1.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock2.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock3.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock4.png" width="98" height="15" border="0" />
</div>

Open in new window

Brad BansnerWeb DeveloperAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
Or (direct children) : $(this).children(".gr_mwc_monthblock")
Or again : $(this).find(".gr_mwc_monthblock")
0
 
leakim971PluritechnicianCommented:
You may use : $("gr_mwc_monthblock", this) to select it



$(function(){
	$('.dayblock').click(function(){
		$('.dayblockhl').removeClass('dayblockhl');
		$('.gr_mwc_monthblockarrowhl').removeClass('gr_mwc_monthblockarrowhl');
		$(this).addClass('dayblockhl');
		$(this).addClass('gr_mwc_monthblockarrowhl');
                $("gr_mwc_monthblock", this).addClass("someclass");
	});
});

<div class="dayblock" id="day_5_8_2011">
	<img class="gr_mwc_monthblockarrow" src="art/gr_mwc_monthblockarrow.png" width="9" height="11" border="0" /> May 8<br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock1.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock2.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock3.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock4.png" width="98" height="15" border="0" />
</div>

Open in new window

0
 
leakim971PluritechnicianCommented:
Correction (class selector : . ) :  $(".gr_mwc_monthblock", this)

$(function(){
	$('.dayblock').click(function(){
		$('.dayblockhl').removeClass('dayblockhl');
		$('.gr_mwc_monthblockarrowhl').removeClass('gr_mwc_monthblockarrowhl');
		$(this).addClass('dayblockhl');
		$(this).addClass('gr_mwc_monthblockarrowhl');
                $(".gr_mwc_monthblock", this).addClass("someclass");
	});
});

<div class="dayblock" id="day_5_8_2011">
	<img class="gr_mwc_monthblockarrow" src="art/gr_mwc_monthblockarrow.png" width="9" height="11" border="0" /> May 8<br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock1.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock2.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock3.png" width="98" height="15" border="0" /><br />
	<img class="gr_mwc_monthblock" src="art/gr_mwc_monthblock4.png" width="98" height="15" border="0" />
</div>

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Brad BansnerWeb DeveloperAuthor Commented:
Fantastic! So, is it correct that this is what you are saying:

select anything with a class of gr_mwc_monthblockarrow within "this"?

That seems counterintuitive to me, because I thought you always start with the parent and drill down to the child.
0
 
Brad BansnerWeb DeveloperAuthor Commented:
I like this best:

$(this).children('.gr_mwc_monthblockarrow').addClass('gr_mwc_monthblockarrowhl');

But thanks again!
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.