1

hi every I writed a line like this:

<a href="#">delete</a>

I want do some in js function when click this,so I use jQuery, and like this

$('a[href='#']').click(function(){
  alert("test");
  return false;
});

I use this to test, but it do best in Firefox, but can't work in IE, why? I could not find the error, could you help me thank you

1
  • Can you give the <a> element a class? Commented Nov 29, 2010 at 19:54

4 Answers 4

6

single quote $('a[href='#']') is closing the string

$("a[href='#']").click(function(){
    alert("test");
    return false;
});
Sign up to request clarification or add additional context in comments.

Comments

2

Because of the quotes.

$("a[href='#']").click(function(){
  alert("test");
  return false;
});

Comments

0

Your quotes are causing the problem.

$('a[href="#"]').click(function(){ alert("test"); return false; });

If you look closely, I have changed the single quotes around the # to double quotes. If you use only single quotes, then JavaScript thinks you are trying to end the quoted string. FireFox is catching the error (correctly) and does not work.

Comments

0

I do it follow your advices,but it also didn't work in IE,so I changed the way,I use the span for href ,like this test and change the css for span,to made it had the style of href Aslo think you very much

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.