// create a jQuery-boosted div
$div = $('<div></div>');
$div.attr('id','someId');
alert($div.attr('id'));
// to get the DOM element:
var div = $div[0];
// or
var div = $div.get(0);
lub po prostu owinąć elementu DOM w $()
jak sugeruje:
$(d).attr('id','someId');
$(d).blah();
Zastosowanie attr
get/set elementem atrybutów. Nie jestem pewien, czy istnieje jeden liniowiec, który może zrzucić wszystkie atrybuty elementu i ich odpowiednie wartości (firebug służy temu celowi), ale możesz utworzyć tablicę ze wszystkimi nazwami atrybutów, które Cię interesują, oraz zrobić coś takiego:
var attr = ['name', 'id', 'src', 'foo'];
var len = attr.length;
for (var i = 0; i < len; i++)
alert($(d).attr(attr[i]));
lub za pomocą $.each
:
$.each(['name', 'id', 'src', 'foo'], function(i,val) {
alert('Attribute: ' + val + ' Value: ' + $(d).attr(val));
});
Jeśli tylko chcesz zobaczyć atrybuty i funkcje związane z $ (d) zrobić console.log ($ (d)), który będzie wydrukuj szczegóły obiektu $ (d) w konsoli firebug. Będzie to działać tylko z firefox z firebug dodać na – Nick