tags:

views:

86

answers:

2

Hey,

I am using this line of code:

initWords($('<span></span>').addClass('word').text(data.word).appendTo('#wordBank'));

Along with creating a <span class="word">word</span> I want too add name="WORD HERE" to the tag.

I see that $(".word").attr("name"), but is this how I set the attr name to the span.word?

Thanks,

Ryan

+4  A: 

To set an attribute use 2 parameters:

$(".word").attr("name", "somevalue");
Andy Gaskell
A: 

If you use

$(".word").attr("name")

you finds the name attribute of the first span in the page.

If you want to set a value using the following syntax:

1) Use "attr(key, value)" to set a single property to a value, the matched element(s):

$("img").attr("key", "value");

2) Use "attr(properties)" to set some attributes for the matched element(s):

$("img").attr({ key1: "value1", key2: "value2" });
ranonE