1
<input id="mnc" type="text"/>
<input type="text" id="selected" />

$('#mnc').val().length ? $('#selected').attr({
    'size': $('#mnc').val()
}) : $('#selected').removeAttr('size');

This gives an error in Firefox 4.

Index or size is negative or greater than the allowed amount" code: "1

Other browsers are able to handle removeAttr even if attribute does not exist. What i'm doing is checking if input #mnc is empty then remove attribute size from #selected whether it exists or not.

Check http://jsfiddle.net/zFCtU/1/

2
  • any particular reason why you are not checking if it exists before removing the attr? Commented Apr 12, 2011 at 23:27
  • This doesn't seem to be the issue. Even if size attribute exists, i'm still getting the error in firefox 4. Commented Apr 12, 2011 at 23:31

3 Answers 3

2

It's a bug in Firefox, see the jQuery bug report. A workaround should be present for jQuery Version >= 1.6.

Edit: Sadly the fix is to be released with 1.6 (not 1.5.2 as I wrote earlier). Firefox 4.0.1 should fix it on the firefox-side though. You either have to decide to expect that 4.0.1 is installed of have to apply the patch yourself.

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

1 Comment

Thanks, i guess will have to wait for jQuery 1.6.
1

here is a snippet to look at, it's working

$('#mnc').change(function () {
    if ($(this).val().length > 0) {
        $('#selected').attr({'size': $(this).val().length});
    } else {
        $('#selected').removeAttr('size');
    }
});

Comments

0

Why don't you try setting it first then unsetting it, to make sure it always exists?

$('#selected').attr('size','').removeAttr('size');

Comments

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.