So I want to check if there is any li element that has a attribute of "data-foo" and its value is "bar".
Would this work? :
if ($('li[data-foo=bar]'))
{
//exists
}
else
{
//does not exist
}
Thanks
So I want to check if there is any li element that has a attribute of "data-foo" and its value is "bar".
Would this work? :
if ($('li[data-foo=bar]'))
{
//exists
}
else
{
//does not exist
}
Thanks
Get length
of elements retured by selector if it is greater
then zero
then it means you have atleast one
element with provided condition in selector.
if ($('li[data-foo=bar]').length > 0)
{
//exists
}
else
{
//does not exist
}