/    Sign up×
Community /Pin to ProfileBookmark

I switched to using this function to create element:
—————————————————-


[CODE]
function elem(name, attrs, style, text) {
var e = document.createElement(name);
if (attrs) {
for (key in attrs) {
if (key == ‘class’) {
e.className = attrs[key];
} else if (key == ‘id’) {
e.id = attrs[key];
} else {
e.setAttribute(key, attrs[key]);
}
}
}
if (style) {
for (key in style) {
e.style[key] = style[key];
}
}
if (text) {
e.appendChild(document.createTextNode(text));
}
return e;
}[/CODE]

———————————————————
so instead of the “old” way:
[COLOR=Navy]var oMyDiv = document.createElement(“DIV”);
oMyDiv.setAttribute(“id”,”testid”);
oMyDiv.className = “testclass”;[/COLOR]

I use that function :
[COLOR=Navy]var oMyDiv = elem(‘DIV’, {‘id’:’testid’, ‘class’:’testclass’});[/COLOR]

Rendered source shows this:
[COLOR=RED] <div extend=” function (object) {return Object.extend.apply(this, [this,object]); } “class=”testclass” id=”testid”>
[/COLOR]

Question: the “EXTEND” part is beyond me……anyways does it look
legit/right ? ?

Any if you please ….put this
[COLOR=RED]extend=” function (object) {return Object.extend.apply(this, [this, object]); } [/COLOR]” in English

thanks

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@CharlesSep 24.2005 — For HTML use:function elem(name, attrs, style, text) {
var e = document.createElement(name[b].toUpperCase()[/b]);
if (attrs) {
for (key in attrs) {
if (key == 'class') {
e.className = attrs[key];
} else if (key == 'id') {
e.id = attrs[key];
} else {
e.setAttribute(key, attrs[key]);
}
}
}
if (style) {
for (key in style) {
e.style[key] = style[key];
}
}
if (text) {
e.appendChild(document.createTextNode(text));
}
return e;
}
For XHTML use function elem(name, attrs, style, text) {
var e = document.createElement(name[b].toLowerCase()[/b]);
if (attrs) {
for (key in attrs) {
if (key == 'class') {
e.className = attrs[key];
} else if (key == 'id') {
e.id = attrs[key];
} else {
e.setAttribute(key, attrs[key]);
}
}
}
if (style) {
for (key in style) {
e.style[key] = style[key];
}
}
if (text) {
e.appendChild(document.createTextNode(text));
}
return e;
}
And what's up with that "extends" stuff?
Copy linkTweet thisAlerts:
@boobieauthorSep 24.2005 — And what's up with that "extends" stuff?[/QUOTE]

? what you mean ? did you read my post ?
Copy linkTweet thisAlerts:
@CharlesSep 24.2005 — :confused: what you mean ? did you read my post ?[/QUOTE]Your post I read but I understood it not. Please clarify.
Copy linkTweet thisAlerts:
@boobieauthorSep 24.2005 — Your post I read but I understood it not. Please clarify.[/QUOTE]
? Charles, Which part of my question you dont understand ?

I even co0lor-coded my post to make it clear.

Rendered source shows this:

[COLOR=Red]<div extend=" function (object) {return Object.extend.apply(this, [this,object]); } "class="testclass" id="testid">[/COLOR][/QUOTE]

[URL=http://jennifermadden.com/scripts/ViewRenderedSource.html]Rendered Source[/URL] : You do know about this FF extension right ?

So like I said I called that function like this:

[COLOR=Navy]

var oMyDiv = elem('DIV', {'id':'testid', 'class':'testclass'});[/COLOR]


and (according to the "Rendered Source" extension) at RUNTIME, FF apparently rendered this:

[COLOR=Red]<div extend=" function (object) {return Object.extend.apply(this, [this,object]); } "class="testclass" id="testid">[/COLOR]

My Questions:

1)Does it look legit.

2) [COLOR=Red]extend=" function (object) {return Object.extend.apply(this, [this,object]); }[/COLOR] in English
Copy linkTweet thisAlerts:
@CharlesSep 24.2005 — 1)Does it look legit.[/QUOTE]No, "extend" is not a valid HTML attribute.
×

Success!

Help @boobie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...