Treehouse: Grow your CSS skills. Land your dream job.

sorting elements

  • # June 9, 2015 at 7:25 am

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

    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)

You must be logged in to reply to this topic.