Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the href of an html tag with css

Tags:

html

css

href

I need to change this A tag from

<a href="contact.html" >Contact</a>

to

<a href="tel:+13174562564" >Contact</a>

with only Css if it's possible or like this

<a href="tel:+13174562564" >+13174562564</a>

i have a lot of pages and i don't want to edit all of them it will take a life time that's why i need to do it in CSS and i have no JS linked to them

like image 554
kais mellah Avatar asked Mar 12 '13 08:03

kais mellah


3 Answers

CSS is display only, you cannot modify the document object model with it. Sorry, this cannot be done. I wish I had a better answer, but 'it cannot be done' is the only answer.

like image 101
jnovack Avatar answered Oct 19 '22 23:10

jnovack


CSS is for presentation and cannot be used to modify the HTML markup in the way you intend. You need JavaScript for this.

It should be a fairly short script.

like image 45
Anirudh Ramanathan Avatar answered Oct 20 '22 00:10

Anirudh Ramanathan


one solution is to hide a tag and put another

<div id="tag1">
<a href="#tag1">link1</a>
<a href="#tag2">link2</a>
</div>

css :

a[href="#tag1"] {
display:block;
}

a[href="#tag2"] {
display:none;
}

#tag1:target  a[href="#tag1"]{
 display:none;
}

#tag1:target  a[href="#tag2"]{
 display:block;
}

I use this method for responsive "buttons" of my menu bar

like image 22
kiwi Avatar answered Oct 20 '22 00:10

kiwi