mephisto4
mephisto4

Reputation: 22

uncaught exception after click event

So I''ve got this jQuery code code:

//some button
var moreButton = $('<a href="#" class="buttonClass">Szczegóły</a>'); 

//load button to the first element with given class
$('.someDiv').first().append(moreButton); 

//after button click we show/hide another div

$(moreButton).on('click', function(e){
    e.preventDefault();
    $('.hiddenDiv').slideToggle();    
});

So everything is working just fine, BUT the console shows this error:

uncaught exception: Invalid arguments

after the click event.

I've tried to remove everything from the click function, leaving only some console.log, but the problem still appears.

Upvotes: 0

Views: 218

Answers (3)

alessandrio
alessandrio

Reputation: 4370

jQuery.noConflict();
(function( $ ) {
  $(function() {
    // More code using $ as alias to jQuery
  });
})(jQuery);

jQuery.noConflict()

or

var $$ = $.noConflict(true);
//some button
var moreButton = $$("<a>",{
    'href': "#",
    'class':"buttonClass",
    'text':"Szczegóły"
});

//load button to the first element with given class
$$('.someDiv').first().append(moreButton);

//after button click we show/hide another div

$$(moreButton).on('click', function(e){
    e.preventDefault();
    $$('.hiddenDiv').slideToggle();
});

Upvotes: -1

mephisto4
mephisto4

Reputation: 22

Ok. It was collision with other code.

What's interesting Safari Developement Tools were more helpful than Firebug.

Upvotes: -2

Yair.R
Yair.R

Reputation: 795

Your code is wrong.. should be like this:

//some button
var moreButton = '<a style="cursor: pointer" class="buttonClass">Szczegóły</a>'; 

This supposed to be a string and not a Jquery call

also:

$('.buttonClass').on('click', function(e){
    e.preventDefault();
    $('.hiddenDiv').slideToggle();    
});

Upvotes: 0

Related Questions