最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - jQuery, how to find an element by attribute NAME? - Stack Overflow

matteradmin16PV0评论

I found many example finding elements by attribute value BUT not with name. I want to find all elements (can be link, button, anything) with the attribute containing deleteuserid. I tried this:

console.log($('[deleteuserid!=""]'));

but this find "everything" which not even containing the deleteuserid attribute...

something like this: jQuery how to find an element based on a data-attribute value? expect that I dont have a concrete value (in other words, I want to find $("ul").find("[data-slide=*]");

I found many example finding elements by attribute value BUT not with name. I want to find all elements (can be link, button, anything) with the attribute containing deleteuserid. I tried this:

console.log($('[deleteuserid!=""]'));

but this find "everything" which not even containing the deleteuserid attribute...

something like this: jQuery how to find an element based on a data-attribute value? expect that I dont have a concrete value (in other words, I want to find $("ul").find("[data-slide=*]");

Share Improve this question edited May 23, 2017 at 12:24 CommunityBot 11 silver badge asked Feb 16, 2016 at 8:31 John SmithJohn Smith 6,19715 gold badges76 silver badges128 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 21

Simply use deleteuserid instead of deleteuserid!="" like following.

console.log($('[deleteuserid]'));

you can use the jquery attribute selector to search by name.

console.log($('[name="deleteuserid"]'));

You can search by simple $('[name="deleteuserid"]')

console.log($('[name="deleteuserid"]'))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p name="deleteuserid">

</p>
<div name="deleteuserid">

</div>
<i name="deleteuserid"></i>
<b></b>

$( "*[name*='deleteuserid']" ).addClass('iFoundyou');

JSFiddle

Reference: https://www.w3schools.com/cssref/sel_attr_begin.asp

My demo: All my selects have id="<f_field_name>"

    <select id="f_type" />
    <select id="f_employee" />
   $('[name="form_monitoria_ligacoes"]').find('[id^="f_"]')

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far