How can I get this code to link through to a website with an onclick event not HTML

Discussion in 'JavaScript' started by nat.jenkins1, Jan 26, 2012.

  1. #1
    this is the code it is not inside html it is javascript only

    function handler_TWTmini4_onClick(mouseev){


    }
     
    nat.jenkins1, Jan 26, 2012 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2

    you can do it via a javascript console, for example Firebug.
    but you will be the only one that can use it, if you intend to make it accessible by other users you need to include it in a script that is already exists in the page..
     
    JohnnySchultz, Jan 30, 2012 IP
  3. nat.jenkins1

    nat.jenkins1 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok but what is the code I need to type into the current code to make it happen? I have not written the code like this before and I can't work it out, sorry I a a real newbee to this.
     
    nat.jenkins1, Jan 30, 2012 IP
  4. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #4
    you need first to identify the element you want to add the onclick event..

    if it has an id attribute, you can use document.getElementById.
    if not you will need to identify it by the nearest element with an id


    the code would be:
    
    
    function handler_TWTmini4_onClick(mouseev){
    
    ...
    
    }
    
    document.getElementById('the_id').onclick = handler_TWTmini4_onClick;
    
    
    Code (markup):
     
    JohnnySchultz, Jan 31, 2012 IP