admin管理员组文章数量:1414908
I have a .button made in css and added to the html 4 times like this
<a class="button icon Call" id="nupp2" href="#"><span>CALL</span></a>
and a .js with the following inside
$(document).ready(function(){
$("nupp2").click(function(){
var name=prompt("Please enter your name","blabla");
});
});
The buttons appear if I open the html with firefox and they change if I hover over them But if I press the button, it doesn't do anything. I didn't forget to point to the files in the html file.
Am I even doing this right? Or is jquery more plex than I think?
I have a .button made in css and added to the html 4 times like this
<a class="button icon Call" id="nupp2" href="#"><span>CALL</span></a>
and a .js with the following inside
$(document).ready(function(){
$("nupp2").click(function(){
var name=prompt("Please enter your name","blabla");
});
});
The buttons appear if I open the html with firefox and they change if I hover over them But if I press the button, it doesn't do anything. I didn't forget to point to the files in the html file.
Am I even doing this right? Or is jquery more plex than I think?
Share Improve this question edited Mar 25, 2011 at 16:02 Prisoner 27.7k11 gold badges76 silver badges103 bronze badges asked Mar 25, 2011 at 16:00 nilsnils 3353 gold badges5 silver badges16 bronze badges 1-
2
You need to use a unique
id
value for each button... otherwise use a class. – prodigitalson Commented Mar 25, 2011 at 16:03
7 Answers
Reset to default 4Selectors in jQuery work a lot like the ones in CSS. $("nupp2")
bees $("#nupp2")
, see?
This is wrong:
$("nupp2").click(function(){
The correct is:
$("#nupp2").click(function(){
The string inside the parens is a jQuery selector. Since you want to select an element by id, the proper selector is a hash sign followed by the id.
you need to add a hash sign (#) before the ID of the element - $('#npp')
You missed the hash on your selector:
$("#nupp2").click(function(){ // <----- #nupp2
var name=prompt("Please enter your name","blabla");
});
To call an ID you need to add a # in front of the selector (Like CSS)
So your jQuery selector should be $("#nupp2")
Just try this
$(document).ready(function(){
$("#nupp2").click(function(){
var name=prompt("Please enter your name","blabla");
});
Try this:
$(document).ready(function(){
$(a#nupp).click(function(){
var name=prompt("Please enter your name","blabla");
});
});
本文标签: javascriptHow to make jquery click() work with css buttonStack Overflow
版权声明:本文标题:javascript - How to make jquery click() work with css button? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745161425a2645457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论