|
|
#1 |
|
jQuery div toggle
So, I have about 7 divs and every div is with different class. I want them to toggle SEPERATELY when I hover across it.
This is the function: Code:
$(".open").hide();
$("div.click").mouseenter(function(){
$(".open").toggleClass("active").animate({width:'toggle'},1000);
});
|
|
|
|
0
|
|
|
#2 |
|
Give all the divs the same class.
To have the function only applied to the one thats hovered over change $(".open") to $(".open", this). Adding this changes the scope to only the element that triggered the function.
__________________
MacBook Pro 13", 2.53ghz C2D, 8GB Ram, 640GB HDD, ML | iPhone 5 32GB | iPad 3 64GB
|
|
|
|
0
|
|
|
#3 |
|
Thanks, I'll try that.
|
|
|
|
0
|
|
|
#4 |
|
Well, it doesn't work
|
|
|
|
0
|
|
|
#5 |
|
I think he meant jQuery(this)
EDIT: Actually I'm not sure what you are intending to do. Are you basically trying to remove the class 'active' from all but the one hovered? I assume all of them start with out any having the class 'active', so on the hover of one just jQuery('.open').removeClass('active'); jQuery(this).addClass('active').animatewhatever... What isn't working about it? Last edited by jared_kipe; Nov 4, 2011 at 10:45 AM. |
|
|
|
0
|
|
|
#6 |
|
(Well I removed the class active, I don't know why did i put it there.)
I have 7 divs with the same class. I want them to toggle on mouseenter. If I hover across one, it will toggle all of them (with the same class) So what do I have to add to toggle seperately? Code:
$(".open").hide();
$("div.click").mouseenter(function(){
$(".open").animate({width:'toggle'},1000);
});
Last edited by Hexiii; Nov 4, 2011 at 10:56 AM. |
|
|
|
0
|
|
|
#7 |
|
So the problem is how do you map some div.click's to the .open's. I don't have enough information to solve this problem.
You need to post code, because I can't tell if there is a parent-child relationship or if they are just completely separate. Code:
<div class="open"><!-- 1 --><div class="click"><!-- 1 --></div></div> <div class="open"><!-- 2 --><div class="click"><!-- 2 --></div></div> <div class="open"><!-- 3 --><div class="click"><!-- 3 --></div></div> Code:
<div class="click"><!-- 1 --></div> <div class="click"><!-- 2 --></div> <div class="click"><!-- 3 --></div> <div class="open"><!-- 1 --></div> <div class="open"><!-- 2 --></div> <div class="open"><!-- 3 --></div> |
|
|
|
0
|
|
|
#8 |
|
Code:
<div id="center"> <div class="click"><a href="#"></a></div> <div class="open"><br> <h3>XXXX</h3> <p><nobr>XXXXX XXXX<nobr></p> </div> <div class="click left"><a href="#"></a></div> <div class="open left"><br> <h3>XXXX</h3> <p><nobr>XXXXX XXXX<nobr></p> </div> </div> |
|
|
|
0
|
|
|
#9 |
|
Easiest modification.
Code:
<div id="center"> <div class="click"><a href="open1"></a></div> <div class="open open1"><br> <h3>XXXX</h3> <p><pre>XXXXX XXXX</pre></p> </div> <div class="click left"><a href="open2"></a></div> <div class="open open2 left"><br> <h3>XXXX</h3> <p><pre>XXXXX XXXX</pre></p> </div> </div> Code:
jQuery("div.click").mouseenter(function(){
var classToOpen = jQuery(this).children('a').attr('href');
jQuery(classToOpen).animate({width:'toggle'},1000);
});
|
|
|
|
0
|
|
|
#10 | |
|
Quote:
/e It doesn't work either. Last edited by Hexiii; Nov 4, 2011 at 12:34 PM. |
||
|
|
0
|
|
|
#11 | |
|
Quote:
EDIT: All this was on the proposition that your previous code WAS working except that it was 'toggling' all of the elements instead of 'toggling' one of them. EDIT2: NVM napkin programming, I thought of the problem. the JS should be like this, I didn't make a complete selector out of the href's. Code:
jQuery("div.click").mouseenter(function(){
var classToOpen = jQuery(this).children('a').attr('href');
jQuery('.' + classToOpen).animate({width:'toggle'},1000);
});
Last edited by jared_kipe; Nov 4, 2011 at 01:04 PM. |
||
|
|
0
|
|
|
#13 |
|
because he uses jQuery(this).next() to find the element that is hidden right after the element that he is using to toggle them. This would work for your html. But not if you reordered it.
|
|
|
|
0
|
|
|
#14 |
|
Yeah, I tried that too, but it didn't work, maybe because one is on the left and one on the right.
|
|
|
|
0
|
|
|
#15 |
|
Well obviously the effect depends on the CSS for the various elements, mainly the container element .open
|
|
|
|
0
|
|
|
#16 |
|
So there isn't any "or" selector in jQuery? something like ("open1"/"open2")
|
|
|
|
0
|
|
|
#17 |
|
What would that acomplish? Would it select both of them?
|
|
|
|
0
|
|
|
#18 |
|
i'd create a separate class for each div and then just put all of them to the jquery
|
|
|
|
0
|
|
|
#19 |
|
Awwww, I found that mistake. I put there <nobr>xxx<nobr> instead of <nobr> xxx </nobr>.
I feel stupid. -.-' |
|
|
|
0
|
|
|
#20 | |
|
Quote:
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| jQuery Selector Question | turbobass | Web Design and Development | 5 | Aug 7, 2011 09:10 PM |
| How can I save div as image where div contains one or more than one HTML5 Canvas? | Somnath | Web Design and Development | 4 | Oct 8, 2010 09:04 AM |
| Expand Parent Div with Size of Child Div | krayziekray | Web Design and Development | 3 | Feb 10, 2010 12:24 PM |
| Centering divs placed in other div :) | chameleon81 | Web Design and Development | 7 | Feb 3, 2010 05:41 PM |
| jQuery, toggle button disable on checkbox change | seventeen | Web Design and Development | 8 | Jul 8, 2009 08:56 AM |
All times are GMT -5. The time now is 03:45 PM.








Linear Mode

