0

So this is what I have right now

http://jsfiddle.net/Wpn94/1755/

The first part of the javascript is just calling in the jQuery lib. Since I don't have acces to the original files I use a custom css, js plugin (mind this all in done in wordpress).

In the fiddle if you click on one the the 'meer' it only opens the one you've clicked. If you press 'minder'it nicely closes the one you've clicked.

Now to the issue, on my testing area if I click one of these buttons the other 5 open as well, which ofcource is not the intended use.

Is there any solution which could fix this? I'mn not able to link to the testing enviroment since it's about a product which isn't released yet, so sadly I do not have permissions to do so.

Possibly the issue:

  $('.wrapper').find('a[href="#"]').on('click', function (e) {

or

$(this).closest('.wrapper').find('.small, .big').toggleClass('small big');

I think the issue is in one of those two. Since I look for the wrapper class which all the 'buttons'have in common.

Any help would be greatly appreciated.

(structure of the element on the test area)

<div class="column withimage ">
  <div class="column-inner">
    <div class="image" style="background-image: url(http://eperium.com.testbyte.nl/wp-content/uploads/2016/08/Icoon_orientatie_v02.png)"></div>
    <div class="txtwrap"><h4><center>ORIËNTATIE</center></h4>
      <div class="wrapper">
        <div class="small">
          <p style="text-align: center;">
            <span style="color: #000000; font-size: 16pt;">title</span><br>
            <span style="color: #000000; font-size: 12pt;">text<br>more text week. </span></p>
        </div>
        <p style="text-align: center;"><a class="btn" href="#">Meer informatie</a></p>
</div>

3 Answers3

3

What are you doing inside this function ?

$('.wrapper').find('a[href="#"]').on('click', function (e) {

You need to toogle your class on $(this) element, not to select all element with jquery again.

ReaperSoon
  • 765
  • 7
  • 23
  • This should be a comment, not an answer. – Andy Tschiersch Oct 05 '16 at 08:22
  • When you check the fiddle you can see what I do inside the function. It basicly changes the text, and toggles the text of the element on click – Robbin van der Jagt Oct 05 '16 at 08:28
  • *"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it **in the question itself.**"* - jsfiddle links help, but should not replace content in the question – freedomn-m Oct 05 '16 at 08:50
1

As closest doesn't seem to be reliable (maybe only in your test area) it is worth a try to navigate to the desired element with .parent()

$(this).parent().parent().find('.small, .big').toggleClass('small big');

If anyone is interested in the differences: Difference between jQuery parent(), parents() and closest() functions. According to this, closest should actually work but parent seems to be the saver way.

Community
  • 1
  • 1
Focki
  • 150
  • 6
  • jQuery .closest() is more than reliable. It goes through parents returning the first matched anchestor (https://api.jquery.com/closest/). If it does not work, then it means that selector was wrong. – Yuri Oct 05 '16 at 09:53
-1

You can use Jquery's findByClass.

$('.className')

This will find all the elements use className.

haiyang
  • 310
  • 3
  • 8