Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
Results 1 to 7 of 7
-
03-25-2016, 08:36 PM #1New 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:
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.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>
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'); });
-
03-28-2016, 06:13 PM #2New 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 thevisibleclass from the current element?Last edited by VIPStephan; 03-28-2016 at 06:43 PM. Reason: corrected formatting
-
03-28-2016, 06:14 PM #3New 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.
-
03-28-2016, 06:44 PM #4The fat guy next door
- Join Date
- Jan 2006
- Location
- Halle (Saale), Germany
- Posts
- 9,808
- Thanks
- 6
- Thanked 1,159 Times in 1,130 Posts
-
Users who have thanked VIPStephan for this post:
freginold (03-28-2016)
-
03-28-2016, 07:16 PM #5New 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!
-
03-28-2016, 10:35 PM #6Regular 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:
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 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>
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.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>
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
-
03-28-2016, 10:58 PM #7The fat guy next door
- Join Date
- Jan 2006
- Location
- Halle (Saale), Germany
- Posts
- 9,808
- Thanks
- 6
- Thanked 1,159 Times in 1,130 Posts



Reply With Quote
