/ / Jquery come rendere un elemento DIV funzionante come html Un collegamento HREF? - jquery, html

Jquery come fare un elemento DIV per funzionare come html Un link HREF? - jquery, html

Mi chiedo come faccio a farmi fare un background div <div id="branding"></div> che contiene anche altri div e elementi per agire come link.

Esiste comunque un elemento div in collegamento con target="_blank" come opzione.

Come posso farlo?

risposte:

0 per risposta № 1

Supponendo che la tua unica necessità sia di aprire un url in una nuova finestra, devi usare window.open

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

Ma la migliore pratica è usare il a tag si.

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


0 per risposta № 2

come detto Jithin, sarà meglio usare il tag a, ma se vuoi usare div allora prova:

script:

$(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")
}
}
});
});

e HTML

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