Reputation: 12275
I have tried to wrap this in a function and cannot get it to work. I am wondering if it is because it is appending something to the body? But here is the script. Any help is greatly appreciated.
$('.showIt').click(function(){
$('body').append("<div class='show'></div>");
});
I would like to put that into a function i can call, but i cant seem to get it to work, This is what i have tried and it fails to work for me.
function create(){
$('body').append("<div class='show'></div>");
});
$('.showIt').click(function(){
create():
});
can someone please help?
Upvotes: 0
Views: 53
Reputation: 62392
function create(){
$('body').append("<div class='show'></div>");
}
$('.showIt').click(function(){
create();
});
after cleaning up your code a bit I don't know why you can't do this.
you did have an extra );
after closing your create()
function though.
Upvotes: 1
Reputation: 1426
This will add a div.show
to body when you'll click on a link/element with class .showIt
function create(){
$('body').append("<div class='show'></div>");
}
$('.showIt').click(function(){
create();
});
In your code you had a });
when you should have }
and :
when ;
should be
Is that what you're looking for?
Upvotes: 2
Reputation: 887469
You have an extra );
.
Get rid of it.
Your first function is written as function create(){ ... });
Upvotes: 4