3 thoughts on “About that jQuery Mobile trick: CORRECTION

  1. Pete Hodgson says:

    I couldn’t help fiddling with this, and came up with a slightly more succinct solution:

    function refreshStyles( $element ) {
        $element.wrap( '<div>' ).parent().page();
        $element.unwrap();
    }
    

    And then I went crazy and made it a little TOO succinct (but still correct):

    function refreshStyles( $element ) {
        $element.wrap( '<div>' ).parent().page().end().unwrap();
    }
    
    • Pete Hodgson says:

      My divs got eaten. Both of those calls to wrap should have a string param specifying a div.

      Maybe wordpress will prefer this way of encoding it: $element.wrap( “<div>” )

      • Daniel says:

        Pete: Nice edit! It’s funny; I realized somewhat later after posting this that the reason my original version didn’t work is that wrap returns the child element, not the parent, and thus going through the trouble of re-querying the DOM for the wrapper wasn’t really necessary (i.e., using parent would do the trick, as you’ve done). Apparently I was too lazy to refactor, though. Also, I fixed your original comment using WordPress’s awesome syntax.

Leave a comment