mak k mak k - 1 year ago 307
jQuery Question

Uncaught TypeError: j$(...).exists is not a function

var selector = '#Id-value_' + index;
var exist = $(selector).exists();

I am getting error for this piece of code.

My document ready function is

$(document).ready( function() {


K48 K48
Answer Source

There is no exists() function in jQuery. But you can quickly write one:

//add a new function to jQuery
jQuery.fn.exists = function(){return this.length>0;}

//now let's test it
if ($(selector).exists()) {
    // Do something
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download