Using a variable as part of a selctor or attribute?

Using a variable as part of a selctor or attribute?

Hi all - I have a var called seashell that starts at 0, and grows by one number every time someone generates a new form on my page. These forms are generated with the id question seashell - so if this is the third question the user has generated, the form has the id 'question3'.  

I'm trying to pick up when these forms are submitted with jquery, but I don't know how to include the var in the selector the way I need to. Here's the code I've tried:

  1. $("#question"+seashell).submit(function(event) {
  2. event.preventDefault
  3. .before('<div class="row full-width"><div class="triangle"></div><div class="section gridfix" id="replaceme"></div></div>');

I also need to take the div that has the id #replaceme and give it the id #answer seashell - again, I don't know how to go about this. here's the code I've tried for that:

  1. $('#replaceme').attr({
  2. id: 'answer'+seashell,
  3. });

Any pointers much appreciated.

Thanks!