Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Как присвоить объекту jquery "левый аттрибут" (https://javascript.ru/forum/jquery/6182-kak-prisvoit-obektu-jquery-levyjj-attribut.html)

satels 16.11.2009 21:29

Как присвоить объекту jquery "левый аттрибут"
 
Допустим, я создаю объект

ex = $('<div></div>');
	//это "левый" аттрибут
	ex.type = 'type1';
	$('#container').append(ex);


Потом при обходе всех детей:
$('#container').children('div').each(function () {
		ex = $(this);
		data[ex.attr('id')] = {
			'type': ex.type,
		}
	});

почему то нету ex.type - undefined

Как мне задать внешний "левый" аттрибут ? Это вообще возможно ?

Octane 16.11.2009 22:20

var ex = $("<div></div>").data("type", "type1");
$('#container').append(ex);
$('#container div').each(function () {
        ex = $(this);
        data[ex.attr("id")] = {
            type: ex.data("type")
        };
});

http://docs.jquery.com/Core/data

satels 16.11.2009 22:30

Благодарю, Octane!


Часовой пояс GMT +3, время: 20:51.