Results 1 to 2 of 2

Thread: Animated expand/collapse doesn't work if ID contains period

  1. #1
    Join Date
    Jun 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Animated expand/collapse doesn't work if ID contains period

    1) Script Title: Animated Collapsible DIV v2.4

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...edcollapse.htm

    3) Describe problem:
    Hi and thanx for a good script!
    The script works fine for me until we decided to use periods (.) in the ID attribute of the DIV to be expanded/collapsed. 'OK, but then don't use periods...' you might say, but unfortunately I have to... Periods are BTW valid in ID attr. according to W3C Spec.

    Works:
    Code:
    <div id="divToBeExpanded">Some content to be expanded/collapsed</div>
    Does not work:
    Code:
    <div id="div.to.be.expanded">Some content to be expanded/collapsed</div>
    Unfortunately, we NEED to have periods in the ID attribute. Any help much appreciated.

    /Claes

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    The issue has to do with dot (.) and certain other characters having special meaning in jQuery, in the case of dot, a CSS class name. The fix per Google Groups is the following:

    Use two backslashes before each special character within the ID inside your jQuery code.

    A backslash in a jQuery selector escapes the next character. But you need
    two of them because backslash is also the escape character for JavaScript
    strings. The first backslash escapes the second one, giving you one actual
    backslash in your string - which then escapes the next character for jQuery.

    Code:
    $('.first\\:\\:second')
    With that said, try the following modified .js file, which should address this issue.
    DD Admin

Bookmarks

Posting Permissions

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