I\'m trying to select all elements that have a data-go-to
attribute that is not empty.
I\'ve tried $(\'[data-go-to!=\"\"]\')
but oddly enou
According to the documentation this should do it
:not([attr="value"])
DEMO
Hope this helps
$('[data-go-to!=""]:[data-go-to]').each(function() {
// Do Your Stuff
});
I'm not sure about a simple selector, but you could use filter()
:
$('[data-go-to]').filter(
function(){
return ($(this).attr('data-go-to').length > 0);
});
JS Fiddle demo.
References:
$('[data-go-to]').filter(function() {
return $(this).data('go-to')!="";
});
Using :not
, .not()
, :empty
etc will only check if the element itself is empty, not the data attribute. For that you will have to filter based on the data attributes value.
FIDDLE
This works for me
$('[attributename]').filter('[attributename!=""]')
$('[data-go-to]:not([data-go-to=""])')
JSBIN