Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use of variables

    Noob here. Please bear with me.http://www.codingforums.com/images/smilies/tongue.gif

    <span title="this is the title">....</span>

    I need to use variables for the title instad of text.

    Please advise. Thank you.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Code:
    <script type="text/javascript">
    var sptitle = "This is title number " + (++counter);
    var spcontents = "Now the number is " + counter;
    document.write('<span title="' + sptitle + '">' + spcontents + '</span>');
    </script>
    Is something like that what you are talking about??

    You could also do it via:
    Code:
    <span id="whatsit">whatever</span>
    ...
    <script type="text/javascript">
    document.getElementById("whatsit").title = "tick " + Math.random() + " tock";
    </script>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks OldPedant.
    Better the first option. It keeps the <span> unique.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    It keeps the <span> unique.
    ??? No more so than the second one. Either set of code could produce the results of the other set. It was all made-up arbitrary code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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