user832375
user832375

Reputation: 89

jQuery change document.location.href in input

is it possible to use jQuery to do that:

if the body has a <div id="wpadminbar"> then change the document.location.href in this input from

<input type="button" onclick="document.location.href='/wp-login.php?action=register';" value="Forum" id="forum">

to

<input type="button" onclick="document.location.href='/forum';" value="Forum" id="forum">

Upvotes: 3

Views: 41830

Answers (3)

brenjt
brenjt

Reputation: 16297

Try

jQuery("#forum").attr("onclick", "document.location.href='/forum'");

Upvotes: 0

Kyle Hotchkiss
Kyle Hotchkiss

Reputation: 11112

You may want to do this in Javascript alone. Instead of changing the links there, try this:

<script type="text/javascript">
 $(document).load(function() {
  $("#forum").click(function() {
   document.location.href="your URL";
  });
 });
</script>

If you can, place that in your <head>

Upvotes: 5

Naftali
Naftali

Reputation: 146310

if($('#wpadminbar').length > 0) {
    $('#forum').attr('onClick', "document.location.href='/forum';");
}

Upvotes: 7

Related Questions