Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2004
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Target an element after on click event appends it to a different location in the DOM

    I have several profiles and images that are related to each other.

    Example:

    Code:
    <div class="row image-row">
    		  <div class="small-12 medium-3 large-3 columns">
    			<div class="pImage">
    			  <img src="#">
    			  <span>+</span> </div>	  
    		  </div>
    			<div class="pTeaser hidden">
    				<h2 class="profile-names white">Name 1</h2>
    <p>Profile</p>
    		  	</div>
    		  <div class="small-12 medium-3 large-3 columns">
    			<div class="pImage">
    			  <img src="#">
    			  <span>+</span> </div>	  
    		  </div>
    			<div class="pTeaser hidden">
    				<h2 class="profile-names white">Name 2</h2>
    <p>Profile 2</p>
    		  	</div> 
    		  <div class="small-12 medium-3 large-3 columns">
    			<div class="pImage">
    			  <img src="#">
    			  <span>+</span> </div>
    		  </div>
    			<div class="pTeaser hidden">
    				<h2 class="profile-names white">Name 3</h2>
    <p>Profile 3</p>
    		  	</div>
    		  <div class="small-12 medium-3 large-3 columns">
    			<div class="pImage">
    			  <img src="#">
    			  <span>+</span> </div>			  
    		  </div>
    			<div class="pTeaser hidden">
    				<h2 class="profile-names white">Name 4</h2>
    <p>Profile 4</p>
    </div>
    </div>
    I have on click events tied to the object clicked using "this" keyword and then toggling the class and appending the now visible content to just below the row containing the profile images.

    Question: I would like to target the 'pTeaser' that WAS relational to the original on click object to remove the class of 'visible' when the user clicks the same image that triggerd the on click or one of the other images that are tied to this function.

    Code:
    $('.image-row div').on("click", function() {
    		$(this).next('.pTeaser').toggleClass('visible').appendTo('.image-row');
    
    });

  2. #2
    New to the CF scene
    Join Date
    Mar 2016
    Location
    USA
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Perhaps a little clarification would help. Are you trying to make the next element in the class visible, while removing the visible class from the current element?
    Last edited by VIPStephan; 03-28-2016 at 06:43 PM. Reason: corrected formatting

  3. #3
    New to the CF scene
    Join Date
    Mar 2016
    Location
    USA
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Apologies for the formatting... getting used to this forum's posting format.

  4. #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    9,808
    Thanks
    6
    Thanked 1,159 Times in 1,130 Posts
    Quote Originally Posted by freginold View Post
    Apologies for the formatting... getting used to this forum's posting format.
    It’s not very obvious but you can use the [ICODE][/ICODE] BB tags to format code inline.

  5. Users who have thanked VIPStephan for this post:

    freginold (03-28-2016)

  6. #5
    New to the CF scene
    Join Date
    Mar 2016
    Location
    USA
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    that looks much better, thanks!

  7. #6
    Regular Coder
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    311
    Thanks
    0
    Thanked 42 Times in 40 Posts
    Your structure seems to be broken as you are nesting them instead of having them siblings, seems like you're missing a LOT of </div>... would also help if the indentation made the least bit of sense...

    Though the train wreck of "bootcrap meets jquery" is likely a good chunk of what's fighting you here. For the life of me I can't even figure out what it is you're trying to do...

    If we properly format your markup, your nesting... did you accidentally forget some </div> in there because where you have:

    Code:
    <div class="row image-row">
    	<div class="small-12 medium-3 large-3 columns">
    		<div class="pImage">
    			<img src="#">
    			<span>+</span> </div>	  
    		</div>
    		<div class="pTeaser hidden">
    			<h2 class="profile-names white">Name 1</h2>
    			<p>Profile</p>
    		</div>
    		<div class="small-12 medium-3 large-3 columns">
    			<div class="pImage">
    				<img src="#">
    				<span>+</span> </div>	  
    			</div>
    			<div class="pTeaser hidden">
    				<h2 class="profile-names white">Name 2</h2>
    				<p>Profile 2</p>
    			</div> 
    			<div class="small-12 medium-3 large-3 columns">
    				<div class="pImage">
    					<img src="#">
    					<span>+</span> </div>
    				</div>
    				<div class="pTeaser hidden">
    					<h2 class="profile-names white">Name 3</h2>
    					<p>Profile 3</p>
    				</div>
    				<div class="small-12 medium-3 large-3 columns">
    					<div class="pImage">
    						<img src="#">
    						<span>+</span> </div>			  
    					</div>
    					<div class="pTeaser hidden">
    						<h2 class="profile-names white">Name 4</h2>
    						<p>Profile 4</p>
    					</div>
    				</div>
    I've got the sneaking suspicion you meant:

    Code:
    <div class="row image-row">
    	<div class="small-12 medium-3 large-3 columns">
    		<div class="pImage">
    			<img src="#">
    			<span>+</span> </div>	  
    		</div>
    		<div class="pTeaser hidden">
    			<h2 class="profile-names white">Name 1</h2>
    			<p>Profile</p>
    		</div>
    	</div>
    	<div class="small-12 medium-3 large-3 columns">
    		<div class="pImage">
    			<img src="#">
    			<span>+</span> </div>	  
    		</div>
    		<div class="pTeaser hidden">
    			<h2 class="profile-names white">Name 2</h2>
    			<p>Profile 2</p>
    		</div> 
    	</div>
    	<div class="small-12 medium-3 large-3 columns">
    		<div class="pImage">
    			<img src="#">
    			<span>+</span> </div>
    		</div>
    		<div class="pTeaser hidden">
    			<h2 class="profile-names white">Name 3</h2>
    			<p>Profile 3</p>
    		</div>
    	</div>
    	<div class="small-12 medium-3 large-3 columns">
    		<div class="pImage">
    			<img src="#">
    			<span>+</span> </div>			  
    		</div>
    		<div class="pTeaser hidden">
    			<h2 class="profile-names white">Name 4</h2>
    			<p>Profile 4</p>
    		</div>
    	</div>
    Though all those endless pointless div and endless pointless classes make me want to punch someone in the face, but that's the ignorant mouth-breathing nonsense known as bootcrap for you; I'd highly suggest you go find a stick to scrape that off with before you track it all over your site's carpets.

    Admittedly, I say the same thing about jquery...

    I really have to ask, WHY would you append an existing element without removing it? That would create multiple instances in two places.... are you sure you didn't mean to clone it? Build a new one from scratch maybe?

    I'm just not getting your usage scenario, and to be frank even the method used to build the markup doesnae make a whole lot of sense. It all reeks of spending more time focused on what it looks like in the markup than it does paying attention to semantics and meanings -- though again, that's bootcrap for you. I still fail to grasp how anyone qualified to make a website could ever even conceive of a legitimate reason to use that asshattery.
    From time to time the accessibility of websites must be refreshed with the blood of designers and owners; it is its natural manure.
    http://www.cutcodedown.com

  8. #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    9,808
    Thanks
    6
    Thanked 1,159 Times in 1,130 Posts
    Quote Originally Posted by deathshadow View Post
    I really have to ask, WHY would you append an existing element without removing it? That would create multiple instances in two places.... are you sure you didn't mean to clone it? Build a new one from scratch maybe?
    I can only assume the OP wants to move the element to the parent/root element to position it or make it show up in a certain place. But whatever they try to do, there are most likely much simpler ways to achieve it.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •