开发者

jQuery - how to set attr for 'this'..?

开发者 https://www.devze.com 2022-12-22 23:36 出处:网络
I was trying to iterate through a collection of objects and was trying to set a开发者_StackOverflow社区n attribute for each of the object.

I was trying to iterate through a collection of objects and was trying to set a开发者_StackOverflow社区n attribute for each of the object.

Here is the code:

$(document).ready(function() 
{
    $('#clickButton').click(function() 
    {
        var hiddenVal = $('#hdnVal').val();

        $('*').find('*[tabindex]').each(function(index) 
        {
            //this.setAttribute('tabindex', hiddenVal + this.getAttribute('tabindex'));
            $(this).attr('tabindex', 'test');
        });
    });
});

I could not set the attribute with $(this).attr('', ''); but the JavaScript way works fine. How can I do it in jQuery?


Setting a string to tabIndex will not work, it must be an integer.

$(this).attr('tabindex', 'test'); 
alert($(this).attr('tabindex')); 
// ^ alerts 0 in IE for me, indicating the default is restored

Try a number:

$(this).attr('tabindex', 1);
alert($(this).attr('tabindex')); 
// ^ alerts 1
0

精彩评论

暂无评论...
验证码 换一张
取 消