Link hrefPropiedad
Objeto Link
Definición y uso
La propiedad href es una cadena de texto de lectura y escritura que puede establecer o devolver la URL completa del documento que se muestra actualmente.
Sintaxis
Establecer la propiedad href:
linkObject.href="URL.html"
Devolver la propiedad href:
linkObject.href
Compatibilidad del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales admiten la propiedad href.
Ejemplo
Ejemplo
Cambiar la hoja de estilos al hacer clic en un botón:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<link id="style1" rel="stylesheet" type="text/css" href="style1.css.html">
<script>
function displayResult(){
document.getElementById("style1").href="style2.css.html";
}
</script>
</head>
<body>
<h1>Página principal de mi sitio web</h1>
<button type="button" onclick="displayResult()">Cambiar hoja de estilos</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<link id="style1" rel="stylesheet" type="text/css" href="style1.css.html">
<script>
function displayResult(){
document.getElementById("style1").href="style2.css.html";
}
</script>
</head>
<body>
<h1>Página principal de mi sitio web</h1>
<button type="button" onclick="displayResult()">Cambiar hoja de estilos</button>
</body>
</html>
Pruébalo »
Objeto Link Otras extensiones