Reputation: 1632
I am using jQuery on button click to show div but don't know why its not working...
HTML:
<input type="button" id="addmoresg" value="Add More" name="button">
<div id="addsg" style="display:none">
<!-- more HTML here -->
</div>
JavaScript:
$(document).ready(function() {
$('.addmoresg').click(function() {
$('.addsg').show("slow");
});
});
jsFiddle demo: http://jsfiddle.net/XGVp3/
I am not getting any result on button click.
Upvotes: 6
Views: 15482
Reputation: 21
just change your code as:
$(document).ready(function() {
$('#addmoresg').click(function() {
$('#addsg').show("slow");
});
});
Basically, you were targeting the class adddsg
(done by a .class
). Since the div has and ID of adddsg
, you need to target using #ID
Hope that helps.
Upvotes: 0
Reputation: 816590
2 problems:
You use class
selectors [docs] (.addmoresg
) instead of id
selectors [docs] (#addmoresg
). Your elements only have id
s, not class
es:
<input type="button" id="addmoresg" value="Add More" name="button">
$('.addmoresg)
would select elements with class="addmoresg"
, e.g.
<input type="button" class="addmoresg" value="Add More" name="button">
jQuery has a great documentation and a list of all possible selectors, with examples.
Upvotes: 8