About that jQuery Mobile trick: CORRECTION

http://philosopherdeveloper.com/posts/jquery-mobile-trick-correction.html

Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: