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.
2 problems:
- You did not select jQuery as library in your demo.
You use
class
selectors [docs] (.addmoresg
) instead ofid
selectors [docs] (#addmoresg
). Your elements only haveid
s, notclass
es:<input type="button" id="addmoresg" value="Add More" name="button">
$('.addmoresg)
would select elements withclass="addmoresg"
, e.g.<input type="button" class="addmoresg" value="Add More" name="button">
Working demo
jQuery has a great documentation and a list of all possible selectors, with examples.
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.
精彩评论