Function does not rotate 2x

1

I have a function selectStep() that receives a onclick per parameter 1 or 2 , it rotates what was passed. The impasse is that I have two divs Content1 and Content2 , both with the same thing. But only the first runs, the second does not repeat.

I'm a beginner, thanks in advance for any kind of help, criticism. Thanks!

SOURCE

    
asked by anonymous 08.11.2016 / 23:57

2 answers

1

When I have this kind of situation, I'd rather use a date attribute to set the target element, as in the example below:

$('[data-target]').click(function(event) {
  event.preventDefault();
  $('.content').hide();
  $($(this).data('target')).show();
});
.content {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="content" id="content1">Lorem Ipsum 1</div>
<div class="content" id="content2">Lorem Ipsum 2</div>
<a href="#" data-target="#content1">1</a>
<a href="#" data-target="#content2">2</a>
<a href="#" data-target=".content">Todos</a>
    
09.11.2016 / 14:31
1

Your code is correct and works fine with jsFiddle.

  • Do not use the onLoad of jsFiddle, it places your code inside a function and the functions that were no longer global, and HTML no longer finds them. The same problem than this other question .
  • add jQuery to jsFiddle, your code needs to load the library

Working: link

    
09.11.2016 / 16:41