When you use the prefix attribute selector [att^=val] then the value cannot be an empty string. https://www.w3.org/TR/selectors-3/#attribute-substrings
The jQuery method .attr(attributeName) returns the value of this attribute for the FIRST element. So in this case it would return the string "23452345". And strings don't have a .remove() method. https://api.jquery.com/attr/#attr1 To select all spans that have the attribute foobar you can use the attribute presence selector [attr]. So in this example it would be span[foobar]. https://www.w3.org/TR/selectors-3/#attribute-representation On Monday 25 March 2024 at 09:53:35 UTC+1 Matt Adams wrote: > How can I select (from Tampermonkey script) all SPAN elements in current > webpage which contain a property "foobar"? > > The assigned value is unimportant. > > So elements like the following should be matched: > > <span aaa="bbb" foobar="23452345" .....>...</span> > > I tried: > > $('span[foobar^=""]').remove(); > > but it didn't work. > > And > > $('span').attr('foobar').remove(); > > didn't work either. > -- You received this message because you are subscribed to the Google Groups "greasemonkey-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/greasemonkey-users/8568128f-5215-42c3-bc46-180f8f19b322n%40googlegroups.com.
