views:

42

answers:

3

I am trying to do 2 things: 1: append a div to the body 2: make all clicks to links class 'editlink' make a popup and not go to their href

Doing just #2 is fine:

$(document).ready(function(){
//  $(body).append("<div>Hello world</div>");
  $("a.editlink").click(function(event){
    alert("Javascript-endabled users should see this");
    event.preventDefault();
  });
});

but if i uncomment the part 1 thing such:

$(document).ready(function(){
  $(body).append("<div>Hello world</div>");
  $("a.editlink").click(function(event){
    alert("Javascript-endabled users should see this");
    event.preventDefault();
  });
});

The div appears as expected but clicking editlink links no longer gives me a popup and navigates to the link's href.

what's going on?

A: 

Ah nevermind... I forgot it's not $(body) but $("body") >_<

Mala
+1  A: 

Did you mean:

$("body")

rather than:

$(body)

?

Can I recommend that you use Firebug to get decent error reporting? You'd have found this very quickly with Firebug.

RichieHindle
thanks for the firebug reference. I actually have it installed but am not sure how to use the error reporting thing
Mala
Enable the `console`. Whenever an uncaught exception happens, a red icon will show in the bottom right corner, and it will count the number of errors. Clicking it will open the console, where you can see what is the exception and where it happened.
Sinan Taifour
thank you! That'll help lots
Mala
+1  A: 

You are missing the quotes for your body tag selector:

$('body').append("<div>Hello world</div>");
CMS