Solution 1 :

yes you can use the attribute selector sth. like:

a[href="http://usefullink1"] {}

you could also use:

a[href~="usefullink"] {}

to match all containing the word “usefullink” in href

Solution 2 :

Use the :nth-child pseudoclass.

Like so : .main p:nth-child(3) a

Solution 3 :

I used attribute selector with a not clause.

.main p a:not([href*="text_in_all_useless_links_but_not_in_usefull_ones"])

Problem :

My html code is as below..

<div class="main">
<div class="sub1">
<p><a href="http://uselesslink1"></a></p>
<p><a href="http://uselesslink2"></a></p>
<div class="sub2">
<p><a href="http://usefullink1"></a>
<a href="http://usefullink2"></a>

I need to access the useful links http://usefullink1 and http://usefullink2 using css selectors and use

.main p a

But doing this I’m able to access both useful links and also the useless links which are inside the div sub1 inside div main.

With the above html structure is it possible to access only the usefull links and not the useless ones using css.

All help is sincerely appreciated.



Comment posted by Arnab

Thanks for the answer but usefulllink is just a word I used to explain what I need, its going to keep changing in different pages with different urls. I will check to see if there is a common text amongst the useful links which does not exist in the useless links

Comment posted by john Smith

looking at your code you could also try

Comment posted by retterBadach


Comment posted by Arnab

@retterBadach really good one, actually better than your provided answer. Though I used attribute selector with a not clause as I got it early.

Comment posted by retterBadach

@Arnab. You must have found some common text which is at least helpful in your example.