How to get jquery object by its custom attribute

user1179442

HTML segment:

<ul id="nav_des">
    <li class="cur">test1<a class="shopping2" data-category-id="1">12</a></li>
    <li>test2<a class="shopping2" data-category-id="2"></a></li>
    <li >test3<a class="shopping2" data-category-id="3"></a></li>
    <li style="margin-bottom:25px; background:none"></li>
</ul>

I want to get the text() of "" which "data-category-id" is 1 (i.e. it is 12 ) . I tried to use attribute selector like this but failed. So I just use "for" loop to get the value, but I don't think it's a good way. How to fix it? thanks

var category_id =1 
$(".shopping2").("data-category-id='"+category_id+"'").show() 
Milind Anantwar

You can use attribute-equals-selector to get elements by their attribute values:

$(".shopping2[data-category-id='"+category_id+"']").show();

Working Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get a custom attribute with jQuery

From Dev

Get a custom attribute with jQuery

From Dev

Get custom attribute value in Jquery?

From Dev

How to get a custom attribute of user object in Parse, swift

From Dev

How i get an object instance's annotation or Custom Attribute?

From Dev

How to get the value of custom HTML attribute using JQuery?

From Dev

How to get the value of input field by custom attribute in jquery

From Dev

How to get class attribute from jQuery object at specified index

From Dev

How to Get Custom Attribute Back?

From Dev

Why does my object lose its resizable attribute and how do I get it back?

From Dev

jquery: get value of custom attribute in drop down

From Dev

passing jquery args from custom attribute to $.get

From Dev

jQuery get multiple data from custom attribute

From Dev

How to get attribute name and its value properly?

From Dev

How do i get the text value of the text box as its title attribute using Jquery?

From Dev

How to get Symbol attribute of an object

From Dev

How to get datatype attribute in jquery?

From Dev

How to get an attribute of element by jquery

From Dev

jquery to get each and every row of table and rename its name attribute

From Dev

Jquery How to read custom attribute value

From Dev

How do I Alter an attribute to change its datatype in Object type?

From Java

How to get a key in a JavaScript object by its value?

From Dev

Get custom attribute from specific object property/field

From Dev

Set a custom object attribute

From Dev

How to set the content of an element to value of its attribute with jQuery

From Dev

How to set the content of an element to value of its attribute with jQuery

From Dev

Jquery, how to select an element by its first position value of an attribute

From Dev

How do I get the value of a @ object attribute?

From Dev

How to get the attribute of a JS object from Java?

Related Related

  1. 1

    Get a custom attribute with jQuery

  2. 2

    Get a custom attribute with jQuery

  3. 3

    Get custom attribute value in Jquery?

  4. 4

    How to get a custom attribute of user object in Parse, swift

  5. 5

    How i get an object instance's annotation or Custom Attribute?

  6. 6

    How to get the value of custom HTML attribute using JQuery?

  7. 7

    How to get the value of input field by custom attribute in jquery

  8. 8

    How to get class attribute from jQuery object at specified index

  9. 9

    How to Get Custom Attribute Back?

  10. 10

    Why does my object lose its resizable attribute and how do I get it back?

  11. 11

    jquery: get value of custom attribute in drop down

  12. 12

    passing jquery args from custom attribute to $.get

  13. 13

    jQuery get multiple data from custom attribute

  14. 14

    How to get attribute name and its value properly?

  15. 15

    How do i get the text value of the text box as its title attribute using Jquery?

  16. 16

    How to get Symbol attribute of an object

  17. 17

    How to get datatype attribute in jquery?

  18. 18

    How to get an attribute of element by jquery

  19. 19

    jquery to get each and every row of table and rename its name attribute

  20. 20

    Jquery How to read custom attribute value

  21. 21

    How do I Alter an attribute to change its datatype in Object type?

  22. 22

    How to get a key in a JavaScript object by its value?

  23. 23

    Get custom attribute from specific object property/field

  24. 24

    Set a custom object attribute

  25. 25

    How to set the content of an element to value of its attribute with jQuery

  26. 26

    How to set the content of an element to value of its attribute with jQuery

  27. 27

    Jquery, how to select an element by its first position value of an attribute

  28. 28

    How do I get the value of a @ object attribute?

  29. 29

    How to get the attribute of a JS object from Java?

HotTag

Archive