1

I am a beginner with jQuery and I'm struggling a little trying to work this out:

So I have something similar to this:

<div class="app">
<div class="app-text"></div>
</div>
<div class="app">
<div class="app-text"></div>
</div>

I want to use jquery to change the color of .app-text but when using .app-text it will also change the app-text in the other div (obviously) so how would I go about just changing just the .app-text within the .app div that is being hovered on. The event needs to be triggered when hovering on .app div.

(there will be quite a number of .app divs on the same page)

asked Aug 7, 2012 at 10:57

3 Answers 3

3

You can use $(selector, context):

$('.app').hover(function(){
 $('.app-text', this).foo()
 }, function(){
 $('.app-text', this).bar()
})
answered Aug 7, 2012 at 11:01
Sign up to request clarification or add additional context in comments.

2 Comments

@Tats_innit Hey bro, Thanks :), how are you?
@Tats_innit haha, me too :)
1
$('.app').hover(function() {
 var text = $(this).find('.app-text');
 ...
});

or, in CSS3 compatible browsers:

.app:hover .app-text {
 color: red;
}
answered Aug 7, 2012 at 11:00

Comments

0

You can access hovered element with this.

Try something like this:

$('.app').hover(function(){ //function on hover-in
 $('.app-text', this).css('color', 'red');
 }, 
 function(){ //function on hover-out
 $('.app-text', this).css('color', 'black');
 });
answered Aug 7, 2012 at 10:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.