javascript - How do I test if an element with a certain ID exists on a page in jQuery? -
javascript - How do I test if an element with a certain ID exists on a page in jQuery? -
in jquery, have written piece of code appears on every page of website.
var d = $('#someelement').offset().top; however, not every page on website has element id of "someelement". unfortunately, on these pages lack such element, no jquery code works.
to solve problem, want test if element on page indeed has id of "someelement" , run code snippet above if there is.
how perform test? test solve problem? give thanks you.
$('#someelement').length homecoming 1 if element exists, 0otherwise.
javascript jquery
Comments
Post a Comment