简体   繁体   中英

uncaught syntaxerror unexpected token . jquery

First of all let me say I'm new to jQuery. I've tried to search for this error on StackOver flow but did not get any answers. I've created a function in jQuery but this is the error I'm getting from Chrome. uncaught syntaxerror unexpected token . jquery

jQuery.fn.viewC = function(){
    return this.each(function(){
    alert("something");
    });
}

And I'm trying to call this from another function like this

$("#sourceId").click(function() {
    $(this).viewC();
})

Is this the correct way to call a function? And finally what is difference between

_tabChanged : function(container) {
    //some code
},

and

jQuery.fn.viewC = function(){
    //some code
}

Are both the same ways to create a function?

It is a little strange you are using both $ and jQuery in one piece of code. Usually you would use $ to refer to jQuery.

Try this:

$.fn.viewC = function(){
  return this.each(function(){
  alert("something");
});

}

Also, I am not sure if this.each will work (not if it is meant to be jQuery).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM