admin管理员组

文章数量:1201569

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_"]')

本文标签: JavaScriptJQueryhow to find an element by attribute NAMEStack Overflow