View Tutorial Metadata Edit Content Revision History Add New Tutorial Add to Watchlist How to check if an id exists using jQuery

How to check if an id exists using jQuery

Below is a simple function that can tell you if a specific ID exists or not :

function id_exists(id)
{
	if ($("#"+id).length == 0)
	{
		return false;
	}
	return true;
}

Talk icons discuss – in the article above, point your mouse over them to reply.
Can't find a relevant Talk icon for what you have to say? See how you can add one...
Note: All the talks and replies are also listed below.


Add a new discussion topic (Only if you don't find it above, duplicates will be removed)


Rating: (0+, 0-) In: jQuery