Your html is invalid: the id
attribute should be unique. When you try to select by id
with $("#idThatIsNotUnique")
it will just find the first element (or potentially the last element in some browsers) with that id
- in your case the input, not the div.
You could use an html5 data-
attribute instead:
<input type="button" data-animate-id="id1" class="element1" value="TextGoesHere"></input>
<div id="id1">This should be animating.</div>
And then JS:
$(".element1").click(function(){
var expander = $(this).attr("data-animate-id");
var expander2 = '#' + expander;
test(expander2);
});