user1139498
user1139498

Reputation: 101

Link a div to a url with javascript

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?

Upvotes: 0

Views: 396

Answers (2)

Alex
Alex

Reputation: 7688

$('#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

Upvotes: 1

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196236

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; }

Upvotes: 3

Related Questions