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

Results 1 to 3 of 3
  1. #1 Make <a href="..."> execute JavaScript instead of redirect? 
    Registered Member
    Join Date
    Dec 2013
    Posts
    256
    Thanks given
    90
    Thanks received
    56
    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  
    Forum Moderator

    Jay Gatsby's Avatar
    Join Date
    Jun 2010
    Posts
    2,025
    Thanks given
    974
    Thanks received
    938
    Rep Power
    3031
    You could just use onclick?

    [Only registered and activated users can see links. ]
    [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
    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:



Thread Information
Users Browsing this Thread

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

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
  •