SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: jQuery IE

  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery IE

    Composing an element like below works fine in Firefox, but IE throws and error?
    I think it doesn't like the class keyword or something?
    anyone?

    Code JavaScript:
    var courseId = $('<span>', {
        class: 'cCourseId r0',
        text: selectedCourse.find('.cCourseId').text()
    }).appendTo(liRequest);

  2. #2
    Forums Designer
    Join Date
    Jun 2004
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try changing second line to this:

    'class': 'cCourseId r0',

  3. #3
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @CyberAlien - that doesn't work either. It compiles now, but jQuery throws an error at runtime.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    I think that you'll need to remove class from the attributes list, and add it afterwards using the addClass method
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,863
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    does specifying className work? You can't specify class because that is a reserved word in JavaScript so JavaScript uses className to refer to the class attribute..
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by felgall View Post
    does specifying className work? You can't specify class because that is a reserved word in JavaScript so JavaScript uses className to refer to the class attribute..
    Yes, className should work well. A simple test confirms

    Code html4strict:
    <html>
    <head>
    <title>test</title>
    <style type="text/css">
    .cCourseId { color: green; }
    .r0 { text-decoration: bold; }
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script>
    $(function () {
        var $selectedCourse = $('[name="selectedCourse"]'),
            $liRequest = $('li#request'),
            courseId = $('<span>', {
                className: 'cCourseId r0',
                text: $selectedCourse.find('.cCourseId').text()
            }).appendTo($liRequest);
    });
    </script>
    </head>
     
    <body> 
    <select name="selectedCourse">
        <option name="course1">Course 1</option>
        <option name="course2" class="cCourseId" selected="selected">Course 2</option>
    </select>
    <ul>
        <li id="request"></li>
    </ul>
    </body>
    </html>

    Note: variables have been renamed so that for example, liRequest is prefixed with $ (as $liRequest) to indicate that it's an actual jQuery object.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, className works


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
  •