Last Updated: February 25, 2016
·
491
· rebyn

$ ( element exists ) { do something }

if ($("#nearby-Shop").length) {
    $("#go-By-some-bear").hide();
};

-Tu.

1 Response
Add your response

FYI: https://coderwall.com/p/un7keg

COPYPASTA OF MY COMMENT:
It may be a good idea to assign the jQuery object to a var, especially if your selector works on a large DOM.

Concider:

var $testDivs = $("#test").find("div");

if ($testDivs.length) {
  //use $testDivs without searching the DOM again
}
over 1 year ago ·