Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript sorting elements

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #203481
    bearhead
    Participant

    I’m trying to create a script that sorts elements by text that is inside them:

    http://codepen.io/bearhead/pen/RPVYVb

    The codepen seems to work as expected… however I ultimately need to apply that javascript to a set of elements that is being echoed out by php.

    When I try to use that same js on the elements that my php code creates, it behaves very oddly. It nearly works when I try to sort ascending (using a “>” operator), but the javascript doesn’t run at all when I use the “<” operator to sort descending. (both operators work without issue in my codepen demo).

    I can’t figure out why the script works in my demo, but fails with elements that my php has created. Is the javascript running before php has done its thing? (I thought php always runs before any client-side stuff). Maybe the text strings that are coming out of php are some how not readable as numbers in javascript?

    EDIT:

    I decided to sort it via php instead of trying to get the js to work.

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.