Reputation: 894
I found a script that I needed for my website, but I can't get it work. Here's the script: http://jsfiddle.net/vVsAn/1/
But when I try use it (live example), it won't work.
Does it matter where I put the script in your HTML? So far I've tried placing it right after the body tag, in head and inside the div, but the result is the same. I do have jQuery linked from Google's library, but it's like there'd be no jQuery at all.
jQuery(document).ready(function(){
jQuery('#hideshow').live('click', function(event) {
jQuery('#lang').toggle('show');
});
});
Pardon my ignorance, I'm very new to JavaScript and jQuery.
Upvotes: 0
Views: 155
Reputation: 5989
Firstly Make sure that you add the Script inside Body tag or in side Head Tag. You should not put script after body tag
Secondly let me know which version of jQuery you are using Live is deprecated since 1.4 and if you are using jquery 1.7+ then use $("..").on instead
Upvotes: 0
Reputation: 2017
jQuery('#hideshow').bind('click', function(event) {
jQuery('#lang').toggle('show');
if($(this).val()=="Hide")
$(this).val("Show")
else
$(this).val("Hide")
});
This can be your best solution
Upvotes: 0
Reputation: 82231
.live
was removed in jquery 1.9
Try using .on
instead:
$(document).on('click', '#hideshow', function(){
//your event function
});
Working Demo with toggling value
Upvotes: 2
Reputation: 2018
Try this:
jQuery(function($){
$(document).bind('click', '#hideshow', function(event) {
$('#lang').toggle('show');
});
});
or
jQuery(function($){
$(document).click('#hideshow', function(event) {
$('#lang').toggle('show');
});
});
Apologies for syntactical slip.
Upvotes: 0
Reputation: 2280
As of jQuery 1.7 'live()' has been deprecated, use .on() instead ( http://api.jquery.com/live/ )
jQuery(document).ready(function(){
jQuery(this).on('click', '#hideshow', function(event) {
jQuery('#lang').toggle('show');
});
});
Also, remove the ':before' you have prior the javascript which is completely out of context.
By convention, the best place to add javascript is to do it in the 'head' tag, but in the absolute you can put it anywhere and it will work as long as jquery is referenced first.
Hope this helps.
Upvotes: 1
Reputation: 388316
You are using jQuery 1.10.2, the live method is removed in jQuery 1.9 so you need to use .on() instead
jQuery(function($){
$(document).on('click', '#hideshow', function(event) {
$('#lang').toggle('show');
});
});
Also since the event is binded to the document object there is no need to use the dom ready handler
$(document).on('click', '#hideshow', function(event) {
$('#lang').toggle('show');
});
Upvotes: 1
Reputation: 654
$(document).ready(function(){
$("#hideshow").click(function(event){
$("p")('#lang').toggle('show');
});
Upvotes: 0
Reputation: 914
live was deprecated, use on click, or even this:
$('#hideshow').click(function(event) {
//your code here
});
Upvotes: 0
Reputation: 6776
Jquery live method deprecated
Version deprecated: 1.7, removed: 1.9
use older jquery or use other method such as on
Upvotes: 0