ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

Help with making my code DRY #120

Closed skey08 closed 9 years ago

skey08 commented 9 years ago

right now I have this function that is turning one css selector off and turning another one on

$("#next.next2").on("click", function(){
  $(".q2.xx").css("display", "none");
  $(".q3.xx").css("display", "block");
})

the problem is I have to repeat it 10 times to apply it to each button. Basically I need a function that makes each of those 3 numbers go up by one each time a button is clicked.

mattscilipoti commented 9 years ago

I expect you can use a common class, shared across all the relevant elements which can be used by your css selector.

skey08 commented 9 years ago

I don't want them all off or on at the same time though, as the current one turns off I am turning the next one on: screen shot 2015-07-14 at 2 27 02 pm

jshawl commented 9 years ago

inside your click handler, use $(this).parent().next() to reference the next form in your HTML