Thread: Make <a href="..."> execute JavaScript instead of redirect?

Results 1 to 4 of 4
  1. #1 Make <a href="..."> execute JavaScript instead of redirect? 
    Registered Member
    Join Date
    Dec 2013
    Posts
    260
    Thanks given
    91
    Thanks received
    57
    Rep Power
    309
    Hi guys,

    I was wondering if there is a way to change the behaviour of my <a> tags using JavaScript?

    For example...

    <a href="something.html" class="button">Click Me</a>

    Where when the user clicks it, a JavaScript function is called taking the href as a parameter?

    Thanks, help is appreciated.
    Reply With Quote  
     

  2. #2  
    All you gotta do is speak on Ye

    Jay Gatsby's Avatar
    Join Date
    Jun 2010
    Posts
    2,111
    Thanks given
    1,001
    Thanks received
    1,213
    Discord
    Harry.#0001
    Rep Power
    5000
    You could just use onclick?

    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    asmr zone pls b quiet
    Tiny Rick's Avatar
    Join Date
    Apr 2013
    Posts
    184
    Thanks given
    24
    Thanks received
    21
    Discord
    bojgdj#8139
    Rep Power
    74
    You could prevent the default

    whateverElementYouWant.click(function(e) {
    e.preventDefault();
    });

    or an easier option, don't use the anchor tag? Just use a span and style it however you want.
    Reply With Quote  
     

  5. Thankful user:


  6. #4  
    Registered Member
    Join Date
    May 2016
    Age
    21
    Posts
    235
    Thanks given
    125
    Thanks received
    39
    Rep Power
    17
    Quote Originally Posted by Tiny Rick View Post
    You could prevent the default

    whateverElementYouWant.click(function(e) {
    e.preventDefault();
    });

    or an easier option, don't use the anchor tag? Just use a span and style it however you want.
    That's jQuery not JavaScript.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 1
    Last Post: 07-09-2014, 02:28 PM
  2. Replies: 1
    Last Post: 07-27-2009, 11:01 PM
  3. Replies: 2
    Last Post: 03-05-2009, 11:04 PM
  4. Replies: 0
    Last Post: 01-19-2009, 06:00 AM
  5. Replies: 47
    Last Post: 05-01-2008, 02:25 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •