Reputation: 335
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 complex than I think?
Upvotes: 0
Views: 1672
Reputation: 2213
Try this:
$(document).ready(function(){
$(a#nupp).click(function(){
var name=prompt("Please enter your name","blabla");
});
});
Upvotes: 0
Reputation: 10879
Just try this
$(document).ready(function(){
$("#nupp2").click(function(){
var name=prompt("Please enter your name","blabla");
});
Upvotes: 1
Reputation: 1804
To call an ID you need to add a # in front of the selector (Like CSS)
So your jQuery selector should be $("#nupp2")
Upvotes: 1
Reputation: 437854
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.
Upvotes: 2
Reputation: 35803
You missed the hash on your selector:
$("#nupp2").click(function(){ // <----- #nupp2
var name=prompt("Please enter your name","blabla");
});
Upvotes: 1
Reputation: 2960
you need to add a hash sign (#) before the ID of the element - $('#npp')
Upvotes: 1
Reputation: 23303
Selectors in jQuery work a lot like the ones in CSS. $("nupp2")
becomes $("#nupp2")
, see?
Upvotes: 4