<a href="example1.com"> innerHTML1 </a> <a href="example2.com"> innerHTML2 </a> <a href="example3.com"> innerHTML3 </a>
I want to style the second only (innerHTML2) using CSS selectors, based on the inner HTML. Is this possible? I've tried using a[value=innerHTML2]
but it doesn't seem to work.
This is not possible using CSS.
You use the general sibling selector (~) in combination with :hover . The ~ combinator separates two selectors and matches the second element only if it is preceded by the first, and both share a common parent.
The inner texts are the string patterns that the HTML tag manifests on the web page. ':' is used to symbolize contains method. Click on the "Find target in page" button to check whether the defined CSS Selector locates the desired element or not.
Type “css=input[type='submit']” (locator value) in Selenium IDE. Click on the Find Button. The “Sign in” button will be highlighted, verifying the locator value. Attribute: Used to create the CSS Selector.
This is not possible using CSS. You can, however, do it using jQuery. There's a nice blog post on it you can read.
It's currently not possible for all browsers with css, but with javascript you can do this
Updated w/ working code. JSFiddle link below:
Initial HTML per @whamsicore:
<a href="example1.com"> innerHTML1 </a> <a href="example2.com"> innerHTML2 </a> <a href="example3.com"> innerHTML3 </a>
JavaScript:
var myEles = document.getElementsByTagName('a'); for(var i=0; i<myEles.length; i++){ if(myEles[i].innerHTML == ' innerHTML2 '){ console.log('gotcha'); //use javascript to style myEles[i].setAttribute('class', "gotcha"); } }
CSS for styling:
/* make this look a bit more visible */ a{ display: block; } .gotcha{ color: red; }
https://jsfiddle.net/kjy112/81qqxj23/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With