Link a div to a url with javascript

404 views Asked by At

I've recently bought a Ning account. You can't edit any html at all.

The only thing you can do is style the original div's with css. There's a custom code feature where you can add javascript.

I have a div called xn_bar_menu_branding. Can this be linked to a url say: google.com using javascript?

2

There are 2 answers

0
Gabriele Petrioli On

If with named you mean that it has an id="xn_bar_menu_branding" then you can do

$('#xn_bar_menu_branding').click(function(){
  window.location.href = 'http://google.com';
});

But this will only work for javascript enabled browsers, and it will also not be good for SEO purposes.


If you want the mouse to change to a hand when it hovers the div you can do that with CSS with this rule

#xn_bar_menu_branding{ cursor: pointer; }
0
Alex On
$('#xn_bar_menu_branding').html('<a href="http://google.com>Google.com</a>"');

This will replace anything in that div with that id with a link to google