Skip to main content

Bug Tracker

Side navigation

#11141 closed bug (wontfix)

Opened January 08, 2012 05:13PM UTC

Closed January 09, 2012 02:01AM UTC

Last modified March 14, 2012 10:16AM UTC

Setting offset attribute using jQuery's shorthand element creation

Reported by: damian Owned by: damian
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

When trying to create a linear gradient in svg I hit the following problem creating a stop element with an offset attribute.

$('<stop />', {
  'offset' : '0%'
});

Which results in the following error:

TypeError: Cannot use 'in' operator to search for 'using' in 0%

However the following works just fine,

$('<stop />').attr('offset', '0%');

Not sure if this is a bug or not, but I thought I'd flag it up any way.

Attachments (0)
Change History (3)

Changed January 08, 2012 05:24PM UTC by rwaldron comment:1

owner: → damian
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate:  http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

Note, this may fall under http://docs.jquery.com/Won't_Fix#SVG.2FXML.2FVML_Bugs

Changed January 09, 2012 01:08AM UTC by gibson042 comment:2

Confirmed: http://jsfiddle.net/6hSe6/

The responsible code is in jQuery.fn.init at line 149: jQuery.fn.attr.call( selector, context, true ) calls jQuery.attr (via jQuery.fn.attr) with pass=true. Which instructs the function to set attributes in jQuery.attrFn (among them, "offset") like jQuery( elem )[ name ]( value ) instead of with setAttribute.

''That'' path leads to jQuery.offset.setOffset, in which line 9066 throws the observed error: if ( "using" in options ) (options in the above example would be '0%').

I'm against adding a lot of code for this, but at minimum we could avoid the error by changing line 9066 to if ( options.using ). And the entire issue could be resolved by adding a parameter to jQuery and jQuery.fn.init that toggles the (pass=)true on line 149.

I suspect that the easy workaround of $("<element/>").attr({key: value, ...}) makes the latter change overkill, but would still appreciate another opinion.

Changed January 09, 2012 02:01AM UTC by rwaldron comment:3

resolution: → wontfix
status: pendingclosed

Considering the research you've done here and that the issue is easily worked around, I'm going to close this and invoke "Won't Fix" as noted here: http://docs.jquery.com/Won't_Fix#SVG.2FXML.2FVML_Bugs