开发者

How to make jquery click() work with css button?

I have a .button made in css and added to th开发者_JS百科e 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 complex than I think?


Selectors in jQuery work a lot like the ones in CSS. $("nupp2") becomes $("#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");
  });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜