SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Simple Question

  1. #1
    SitePoint Zealot jooles's Avatar
    Join Date
    Jun 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Question

    Hi. I just started learning JS after years of being lazy and deeming it "too difficult".

    So I bumped into one problem. I like using onclick combined with a function to change the properties of certain things (IMG, A, etc.)

    One think I want to be able to do is make it so I can use onclick with a <a href>link</a>

    When I try something like:

    <a href= onclick="change_src()">click me</a>

    It just doesn't work out. I want to be able to use a <a href>link</a> because it has the nice hoverover of a handpointer and users are more inclined to click links like this. How can I combine an a href with an onclick function call???

  2. #2
    SitePoint Zealot jooles's Avatar
    Join Date
    Jun 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <span style="cursor:hand; text-decoration: underline; color: blue;" onclick="changeImage()" >link</span>

    I just figured out a way to do it by changing the cursor property, but this seems like a hack. Is there another way you're supposed to do this?

    Also, what tags are conventionally used to go around stuff in javascript. I noticed you can embed onWHATEVER called functions using just about any html tag.

    <p>? <div>? <???>

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <a href="#" onclick="doSomething(); return false;">my link</a>
    
    function doSomething() {
        // do something
    }
    The above will trigger the doSometing function. Not that the href will not be followed if you have return false like in the above example.

    Also note that you can easily style any element with CSS to look like a link. Meaning hover effect and pointer cursor.

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, event handling is supported on all tags. Depends on how your HTML looks like and what you want to achieve.

  5. #5
    SitePoint Zealot jooles's Avatar
    Join Date
    Jun 2006
    Posts
    144
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any idea how to get the cursor property to work in FF?

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, it's cursor: pointer. cursor: hand is actually incorrect. pointer works in IE as well since version 6.

  7. #7
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need "cursor: hand" for IE versions 5 and below, IIRC. "cursor: pointer" works fine for everything else though.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •