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 2 of 2
  1. #1
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Question Jquery .text help appending

    Hey all i am trying to append to a .text part of this code here:
    Code:
    function buildEventText(event, element) {
    $("<span class='event-title' />")
         .text('4:00pm ').css("color", "red")
         .text('blah').css("color", "blue")
         //.text.append(event.title)
        .appendTo(element);
    }
    But i am unable to do so. It just takes the last .text (in this case, the blah text). I need it to have red for the 4:00 text and then blue for everything else.

    I just can not seem to get it to work correctly.

    Any help would be great!

    David

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Each time you add to the chain it applies to the returning object preceding it. So chaining a second .text() onto the object is overwriting the first .text(). I think... I would do .append twice, once for each color.


  •  

    Posting Permissions

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