/ / ¿Cómo hacer que un elemento DIV funcione como html A HREF link? - jquery, html

¿Cómo hacer que un elemento DIV funcione como html A HREF link? - jquery, html

Me pregunto cómo puedo hacer un div de fondo llamado <div id="branding"></div> que también contiene otros divs y elementos para que actúen como enlace.

¿Hay alguna forma de hacer que un elemento div actúe como un enlace con target="_blank" como opcion

¿Cómo puedo hacer eso?

Respuestas

0 para la respuesta № 1

Suponiendo que su única necesidad es abrir una url en una nueva ventana, necesita usar window.open

$("#branding").click(function(){
window.open(your_url, "_blank");
});

Pero la mejor práctica es usar el a tag sí mismo.

<a href="your_url" target="_blank">...<a>


0 para la respuesta № 2

como dijo Jithin, será mejor usar la etiqueta a, pero si quieres usar div, prueba:

guión:

$(function(){
$("div").click(function(){
if($(this).attr("href")){
if($(this).attr("target") && ($(this).attr("target")!="" || $(this).attr("target")!="_self")){
var _hwnd = window.open($(this).attr("href"), ($(this).attr("target"), "random_word");
}else{
window.location = $(this).attr("href")
}
}
});
});

y HTML

<div class="hyperlink" target="_blank" href="host_controller.php/myroute/myparams">click here</a>