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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    Question Trying to sort, can't get it to work

    Hello, everyone.

    I am trying to sort something that isn't starting as an array, but I'm trying to make it into an array, sort it, then put it back as a string.

    I have a SELECT tag that allows multiple selections, and an "ADD" button that calls a function that will populate an empty div with the TEXT of whatever was selected, separating each selection with "<br />". So, let's say that three options were highlighted and the add button clicked. The div would then look like this (in code, anyway.)
    Code:
    <div id="selectedDevs">Jack Black<br />ZZTop<br />Madonna</div>
    This much is working great.

    But I'm trying to use jQuery to sort the values.

    Code:
    $('#selectedDevs').html($('#selectedDevs').html().split('<br />').sort().join('<br />'));
    It does not change anything. Any suggestions?

    Thank you,
    Last edited by WolfShade; 10-10-2012 at 08:53 PM.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I fixed it, but I don't know why it's working.

    All I did was replace <br /> with <BR> in the split.

    Code:
    $('#selectedDevs').html($('#selectedDevs').html().split('<BR>').sort().join('<br />'));
    The split was not seeing <br />, for some reason.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,286
    Thanks
    12
    Thanked 343 Times in 339 Posts
    HTML does not have a <BR /> element. upon reading in an XHTML document through the HTML parser (which is not done only when the document is served with an XHTML MIME-Type) the elements are converted to valid HTML elements, i.e. <BR> (and that is what is read by the .html() method).

    in short, JS accesses the parsed HTML document, not the written source code.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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