0

I am using this plugin for jQuery.

The plugin tries to create an anchor (<a>) tag, with a value= attribute. However, it does not create the tag with any such attribute in my browser. Is this a jQuery problem? Or an HTML problem? I'm not sure why it seems to be working for so many others, but not for me.

Here is the code I'm using:

$("<a/>").prop({
      className: "ui-rating-star ui-rating-empty",
      title: $(this).text(),   // perserve the option text as a title.
      value: this.value        // perserve the value.
}).appendTo(elm);

This is supposed to create the following element:

<a class=​"ui-rating-star ui-rating-empty" title=​"1 Star">​</a>​

I am using jQuery v1.9.1, if that matters.

Troy Alford
  • 26,660
  • 10
  • 64
  • 82
f0ster
  • 549
  • 3
  • 12
  • 1
    As an aside, why are you setting a `value` on an anchor element anyway? – nnnnnn May 03 '13 at 22:11
  • well I didn't write the code, I am debugging the broken script from the github URL – f0ster May 03 '13 at 22:12
  • OK, fair enough. Note that properties and attributes aren't the same thing. If you try to retrieve the _property_ after it is set does it work? `$("a.ui-rating-star").prop("value")`? (or whatever selector gets the new element) – nnnnnn May 03 '13 at 22:14
  • [Prop vs Attr](http://stackoverflow.com/questions/5874652/prop-vs-attr). – The Alpha May 03 '13 at 22:17
  • @nnnnnn no, because it would be an attr and not a prop – f0ster May 03 '13 at 22:38

1 Answers1

4

.prop only sets properties, not attributes. If an attribute is created, the browser did it not jQuery.

http://api.jquery.com/prop/

Kevin B
  • 94,570
  • 16
  • 163
  • 180
  • Thank you, I didnt' even notice. Though this wasn't my code to begin with, I am now using attr and it works fine. – f0ster May 03 '13 at 22:15
  • +1 When i tried .prop() i was expecting it not to put the attributes but it created the element with attributes so i was wondering.. SO its the Browser.... – PSL May 03 '13 at 22:48