Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    14
    Member #
    25639
    Code:
    <script>    $(document).ready(function() {
     
            var $alertdiv = $('<div id = "alertmsg"/>');
    
           $alertdiv.text("Text here.");
    
            $alertdiv.bind('click', function() {
    
                $(this).slideUp(200);
    
            });
    
            $(document.body).append($alertdiv);
    
            $("#alertmsg").slideDown("slow");
    
            setTimeout(function() { $alertdiv.slideUp(200) }, 9000);
    
        });
    
    </script>
    How does one add hyperlinks into the displayed text?

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    You'll want to change your code around slightly.
    Code:
    var $alertdiv = $("div").attr ("id", "alertmsg");
    var linkCode = "<a href=\"whatever_your_link_is\">Click here or little pink bunnies with pitchforks will stab you.</a>";
    $alertdiv.append(linkCode);
    You may want to edit my anchor text as well. Or keep it. It's your call. If you keep it, I want to see it in action, though.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    14
    Member #
    25639
    Does
    Code:
    var $alertdiv = $("div").attr ("id", "alertmsg");
    replace
    Code:
    var $alertdiv = $('<div id = "alertmsg"/>');
    and the new "var linkCode" portion immediately follows "var $alertdiv"? Not too familiar with JS, unfortunately. Thanks for your help.

  5. #4
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    You know more than you think you do. You've already figured that part out.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  6. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    14
    Member #
    25639
    I did just that (and more afterward) but not even the previous text showed up. :unsure: Is linkCode
    Code:
    $alertdiv.append(linkCode);
    suppose to be surrounded by quotes? Didn't seem to effect the result with or without.

  7. #6
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Nope. It shouldn't be surrounded by quotes because it's your variable.

    I just realized part of yyour problem. You don't need to declare your variable as $alertdiv. Just call it alertdiv. That might be throwing the whole works off.

    So instead of $alertdiv.append(linkCode), you want alertdiv.append(linkCode).

    Give that a whirl and see where it takes you.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  8. #7
    Junior Member
    Join Date
    Dec 2010
    Posts
    14
    Member #
    25639
    Here's the code with changes so far (nothing showing still):
    Code:
    <script>    $(document).ready(function() {
    
    //     var $alertdiv = $('<div id = "alertmsg"/>');
        var $alertdiv = $("div").attr ("id", "alertmsg");
        var linkCode = "<a href=\"whatever_your_link_is\">Click here or else...</a>";
        alertdiv.append(linkCode);
    
            $alertdiv.text("Text here.");
            $alertdiv.bind('click', function() {
                $(this).slideUp(200);
            });
            $(document.body).append($alertdiv);
            $("#alertmsg").slideDown("slow");
            setTimeout(function() { $alertdiv.slideUp(200) }, 9000);
    
        });
    </script>

  9. #8
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Use alertdiv instead of $alertdiv across the board.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  10. #9
    Junior Member
    Join Date
    Dec 2010
    Posts
    14
    Member #
    25639
    alertdivs replaced, but the result is still blank.
    Code:
    <script>    $(document).ready(function() {
    
    //     var $alertdiv = $('<div id = "alertmsg"/>');
        var alertdiv = $("div").attr ("id", "alertmsg");
        var linkCode = "<a href=\"whatever_your_link_is\">Click here or else...</a>";
        alertdiv.append(linkCode);
    
            alertdiv.text("Text here.");
            alertdiv.bind('click', function() {
                $(this).slideUp(200);
            });
            $(document.body).append(alertdiv);
            $("#alertmsg").slideDown("slow");
            setTimeout(function() { alertdiv.slideUp(200) }, 9000);
    
        });
    </script>

  11. #10
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    Upload your page somewhere...it'll help if we can see it. That does look like it should work.

    But before you do that, what happens when you comment out the alertdiv.text line? It comes after the append line. Maybe that's what's interfering.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

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

Search tags for this page

json adding hyperlink

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:18 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com