LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2022, 06:32 PM   #1
starkid
Member
 
Registered: Jan 2012
Posts: 60

Rep: Reputation: Disabled
Question CSS: How to create an Attribute Selector with Multiple Values?


I want to select links whose "data-url" attribute contains at least one of 4 values.

I have tried this:

Code:
a[data-url*="fandom" "deviantart" "anime" "furry" i]
I've also tried it with commas between the quoted values and with | between the quoted values. None of them work.

Do I need to write a separate selector for each value?

I've also tried reading through the W3c and mozilla developer docs; this doesn't seem to be covered.

https://developer.mozilla.org/en-US/...bute_selectors
https://w3c.github.io/csswg-drafts/s...bute-selectors

Last edited by starkid; 09-20-2022 at 07:05 PM. Reason: added info
 
Old 09-21-2022, 08:01 AM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 2,795

Rep: Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049Reputation: 2049
Quote:
Originally Posted by starkid View Post
I want to select links whose "data-url" attribute contains at least one of 4 values.
You can't do that with a single selector.

To select elements where ANY of those match you need four separate selectors (which are themselves comma-separated), i.e:
Code:
a[data-url*="fandom"] , a[data-url*="deviantart"] , a[data-url*="anime"] , a[data-url*="furry"]
To select ALL of them, filter the attribute multiple times:
Code:
a[data-url*="fandom"][data-url*="deviantart"][data-url*="anime"][data-url*="furry"]

However, depending on the context, beware that such simple keyword searching may select more than is intended - not every instance of the five characters "anime" is going to be refer to Japanese animation, the word "accompaniment" being one example.

 
  


Reply

Tags
css


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to create a new Attribute in OpenLDAP and map it with existing attribute kovvuri Linux - Kernel 1 02-19-2020 12:43 PM
[SOLVED] ldap_add undefined attribute type (17) additional info attribute type undefined yashfire007 Linux - Newbie 6 03-20-2015 09:12 AM
How do I modify 1 of my ldap attribute if I have 2 same attribute under 1 entry? chinho Programming 1 01-31-2011 03:37 AM
update problem "Attribute error object has no attribute 'rsplit' ruse Linux - Newbie 0 08-28-2009 01:46 AM
ldap_add: Undefined attribute type (17) additional info: ojectclass: attribute type vinaytp Linux - Newbie 2 05-28-2009 04:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration