jQuery: Seleccionar todos los elementos donde el atributo es mayor que un valor
Sé que para filtrar un elemento con un atttribute llamado attrName que tiene valor attrValue lo hago:
filter("[attrName='attrValue']")
Pero mirando los documentos http://api.jquery.com/category/selectors / No puedo ver una opción para seleccionar todos los elementos s. t. attrName>attrValue
Funcionará
filter("[attrName>'attrValue']")
57
3 answers
Puede hacer esto usando la sobrecarga de funciones de .filter()
, así:
.filter(function() {
return $(this).attr("attrName") > "someValue";
})
91
Author: Nick Craver,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-04-10 14:14:38
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-04-10 14:14:38
La solución es jQuery.filtro():
$("selector").filter(function() {
return $(this).attr("my-attr") > 123;
});
23
Author: Crozin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-04-10 14:18:12
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-04-10 14:18:12
Tenga cuidado, si usted está jugando con números enteros asegúrese de que está utilizando parseInt()
.
$("selector").filter(function() {
return parseInt($(this).attr("my-attr")) > 123;
});
10
Author: Julien Le Coupanec,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-10 19:40:04
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-10 19:40:04