1

In html I have on table like this:

<table for="availableTimeRanges"></table>

then I user jquery to find the table

var table = $("table[for='availableTimeRanges']");

In firefox and chrome, this works,can return the table, but in IE8, nothing return Then i run below code in IE8, found the attribute value is empty:

$.each($("table"), function(i,n){
        alert($(n).attr("for")

});

what's the reason

1
  • 2
    for is not a custom attribute - it's an existing attribute (it is defined in the standard), but you're misusing it on the TABLE element. Commented Aug 18, 2011 at 15:16

4 Answers 4

1

To add to what Šime Vidas said, Try Changing the name from for to something else like forparam, htmlfor, etc. (You can not use for with a table its for labels that are for an input)

$(function () {

        $('table[forparam=availableTimeRanges]').each(function () {
            alert($(this).attr('forparam'));
        });

    });
Sign up to request clarification or add additional context in comments.

Comments

1

You better use class names they are supported everywhere

<table class="for_availableTimeRanges"></table>

and

$('.for_availableTimeRanges')

Comments

0

In think you should try wrapping your code in $(function(){...});

$(function(){
   $.each($("table"), function(i,n){
        alert($(n).attr("for")
   });
});

Comments

0
<table data-ranges="availableTimeRanges"> </table>

var ranges = {
  set : function (options){
     options = options || [];
     //loop and set ranges
  },
  get : function(){
     $("table [data-ranges='availableTimeRanges']").each(function(){
         alert($(this).data("ranges"));
     }); 
  }
};
ranges.get // calls get method

1 Comment

A little explanation would be great :) On SO people tend to want to know "why" :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.