Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:data() selector should be recognized?

I am using jquery-1.11.1 and I try to use the :data selector, described on

https://api.jqueryui.com/data-selector/

trying to find all elements having a certain key like this:

var elements = $(':data(kendoMobileScroller)');

but all I get is an error saying:

Error: Syntax error, unrecognized expression: unsupported pseudo: data

Shouldn´t there be such a selector?

like image 739
Anders Lindén Avatar asked May 06 '14 12:05

Anders Lindén


1 Answers

You need to include jQuery UI in order to get :data pseudo selector working, e.g:

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>

Or just extend jQuery:

$.extend( $.expr[ ":" ], {
    data: $.expr.createPseudo ?
        $.expr.createPseudo(function( dataName ) {
            return function( elem ) {
                return !!$.data( elem, dataName );
            };
        }) :
        // support: jQuery <1.8
        function( elem, i, match ) {
            return !!$.data( elem, match[ 3 ] );
        }
});

DEMO

like image 179
A. Wolff Avatar answered Oct 30 '22 08:10

A. Wolff