Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11141 closed bug (wontfix)

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.

Change History (3)

comment:1 Changed 7 years ago by Rick Waldron

Owner: set to 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

comment:2 Changed 7 years ago by gibson042

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.

comment:3 Changed 7 years ago by Rick Waldron

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

Note: See TracTickets for help on using tickets.