0

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?

1
  • 2
    You need to use a unique id value for each button... otherwise use a class. Commented Mar 25, 2011 at 16:03

7 Answers 7

4

Selectors in jQuery work a lot like the ones in CSS. $("nupp2") becomes $("#nupp2"), see?

Sign up to request clarification or add additional context in comments.

1 Comment

and if the OP would like to call it by the classname, just use $(".classNameHere")
2

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.

Comments

1

you need to add a hash sign (#) before the ID of the element - $('#npp')

Comments

1

You missed the hash on your selector:

$("#nupp2").click(function(){        // <----- #nupp2
    var name=prompt("Please enter your name","blabla");
});

Comments

1

To call an ID you need to add a # in front of the selector (Like CSS)

So your jQuery selector should be $("#nupp2")

Comments

1

Just try this

$(document).ready(function(){
  $("#nupp2").click(function(){
      var name=prompt("Please enter your name","blabla");
  });

Comments

0

Try this:

 $(document).ready(function(){
  $(a#nupp).click(function(){
      var name=prompt("Please enter your name","blabla");
  });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.