Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Jquery change div with .this outside parent
Old 06-22-2012, 01:10 PM Jquery change div with .this outside parent
Experienced Talker

Posts: 47
Trades: 0
Ok, the title might sound a bit strange but i dont really know how to describe my problem in one sentence .
Im working on a little project where i have page where i can add dynamic divs and the dynamic div's include (.load) a html page with jquery.


Ill just show a sample code from what i have.

So a html page is loaded into a dynamic added div, code from the loaded html page:
Code:
<div id="container"> <!-- container -->  

	<div id="overlay">
  		<button id="clear-overlay">Clear</button>
	</div>

    <button id="show-overlay">Show</button> <
				
</div>	 <!-- end container-->
So i have a div.container with a div.overlay inside it, which is (like the id) a overlay (positioned on top with z-index) with a button to clear/hide the overlay.

Jquery code to hide (well fadeOut) the overlay which works like it should:
Code:
    $("#clear-overlay").live("click",function(){
    $(this).parent().fadeOut(1600); 
    });
But now i want to show(fadeIn) the overlay back again with the button inside the div.container and i have no clue how to do this.
Well i think (well maybe not) its something like (this).parent().children() or something but i cant figure it out and cant find any information on the web about it. And i cant use the id from the overlay div because it would show/fadeIn the overlays on all the added div's.

So im hoping this makes sense and someone here knows a solution for it, thnx in advance.

Last edited by TheSir; 06-22-2012 at 01:11 PM..
TheSir is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-22-2012, 03:05 PM Re: Jquery change div with .this outside parent
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
First off, IDs should be unique. So if you have several such containers the overlays and buttons should have the same class, not the same ID.

And for the actual question, the children() function can take an optional parameter to filter the elements it returns, i.e.

$(this).parent().children(".overlay")

Also, I think ther's a previous() function or similar, which would find the element before the current one. You could use it like $(this).previous(). But I'm no sure about that one, try searching on http://docs.jquery.com
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 06-22-2012, 04:01 PM Re: Jquery change div with .this outside parent
Experienced Talker

Posts: 47
Trades: 0
thnx for responding! hmm thanks for reminding that about id's, always forget it but it's a project just for myself so shouldn't really matter i think.

$(this).parent().children(".overlay") works indeed like a charm, dont know why i didn't think of that in the first place. thnx a lot!

Last edited by TheSir; 06-22-2012 at 04:03 PM..
TheSir is offline
Reply With Quote
View Public Profile
 
Old 06-22-2012, 05:21 PM Re: Jquery change div with .this outside parent
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Quote:
Originally Posted by TheSir View Post
thnx for responding! hmm thanks for reminding that about id's, always forget it but it's a project just for myself so shouldn't really matter i think.
It probably does matter. The reason an id must be unique is because it is supposed to uniquely point out exactly one element in the document. So you can't, i.e. find an element with jquery with $("#some_id") if several elements share that id. I don't know what jquery would actually do in such a case, but I guess it won't work very well.


Quote:
Originally Posted by TheSir View Post
$(this).parent().children(".overlay") works indeed like a charm, dont know why i didn't think of that in the first place. thnx a lot!
Glad that it worked out for you.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to Jquery change div with .this outside parent
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16789 seconds with 11 queries