jquery - Check if selector is defined -


i have following plot function:

function plot(selector, data) {   var context = selector.get(0).getcontext("2d");   var wrapper = $(selector).parent(); } 

and on javascript main file have following:

plot($('#pageviews'), data); 

in pages not pageviews item error: typeerror: selector.get(...) undefined

how can check, inside plot function, if selector defined?

and if undefined exit plot function.

thank you, miguel

you can use .length check selector exists or not:

if (selector.length > 0){   // here } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -