Friday, 15 August 2014

javascript - Jquery data Attribute conditional Selector -



javascript - Jquery data Attribute conditional Selector -

how can dom attribute data-"value" in grater 100 , less 500

<div id="bg1" data-50="background-position:0px 0px;" data-end="background-position:-500px -10000px;"></div> <div id="bg2" data-200="background-position:0px 0px;" data-end="background-position:-500px -8000px;"></div> <div id="bg3" data-300="background-position:0px 0px;" data-end="background-position:-500px -6000px;"></div> <div id="bg4" data-600="background-position:0px 0px;" data-end="background-position:-500px -10000px;"></div> <div id="bg5" data-150="background-position:0px 0px;" data-end="background-position:-500px -8000px;"></div> <div id="bg6" data-800="background-position:0px 0px;" data-end="background-position:-500px -6000px;"></div>

you misusing data-* attributes. attribute selectors filter elements attribute's value not attribute's name. there no predefined selector here. iterate through attributes , hard way:

$('div').filter(function() { var = this.attributes, l = a.length, n; (var = 0; < l; i++) { if ( a[i].name.match(/^data-[0-9]+$/) ) { n = + a[i].name.replace('data-', ''); homecoming n > 100 && n < 500; } } homecoming false; });

http://jsfiddle.net/jonpom9m/

javascript jquery

No comments:

Post a Comment