/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] character replacement problem

Here’s the function:

[code]js.attr = function () {
var a = arguments;
var e = a[0];
var v = a[2];
var r = null;
a = a[1].toLowerCase();
if (js.def.obj(e, “dom”) && js.def.txt(a) && a !== “”) {
var s = ‘<‘ + e.nodeName.toLowerCase();
var l = s;
var c = e.attributes;
var o = true;
var n = “”, t = “”;
var d = true;
for (var i = 0;i < c.length;i++) {
n = c[i].nodeName.toLowerCase();
if (e.getAttribute(n)) {
t = c[i].nodeValue;
if (js.def.bol(t)) t = n;
l += ‘ ‘ + n + ‘=”‘ + t + ‘”‘;
if (n === a) {
if (js.def.txt(v)) {
o = false;
if (v !== “”) {
s += ‘ ‘ + n + ‘=”‘ + v + ‘”‘;
r = v;
}
} else if (t !== “”) r = t;
d = false;
} if (t === “”) o = false;
if (o) s += ‘ ‘ + n + ‘=”‘ + t + ‘”‘;
o = true;
}
} t = ‘>’ + e.innerHTML + ‘</’ + e.nodeName.toLowerCase() + ‘>’;
if (d && js.def.txt(v) && v !== “”) s += ‘ ‘ + a + ‘=”‘ + v + ‘”‘;
s += t; l += t;
o = e.parentNode;
v = o.innerHTML;
d = false;
t = false;
n = null;
for (i = 0;i < v.length;i++) {
if (d) {
if (t) {
if (!n) {
if (v[i] === ‘”‘) {
n = ‘”‘;
} else {
n = ‘ ‘;
v = v.substr(0, i) + ‘”‘ + v.substr(i);
} i++;
} if (v[i] === n) {
if (n === ‘ ‘) {
v = v.substr(0, i) + ‘”‘ + v.substr(i);
i++;
}
n = null;
t = false;
}
} else {
v[i] = v[i].toLowerCase();
if (v[i] === ‘>’) d = false;
else if (v[i] === ‘=’) t = true;
}
} if (v[i] === ‘<‘) d = true;
} v.replace(/ [a-z]+=(“”)? /, ” “);alert(v);
o.innerHTML = v.replace(l, s);
} return r;
};[/code]

My problem is that the tag name/s is not converted to lower case by force as it/they should be. every time I try the function the alert box produces html with upper case tags (this is IE by the way), the reason I’m not using getAttribute and related functions is because of IE’s problems. only reason that I’m converting case at all is because not all browsers produce the same case so I want to force the case to a single standard.

Edit: indecently this is part of a framework I’m building so feel free to use it if you think of a fix.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineOct 05.2010 — [CODE]v[i] = v[i].toLowerCase();[/CODE][/QUOTE]In JS it is not possible to change characters in a string; you must build a new string overwriting the original.

[CODE]v.replace(/ [a-z]+=("")? /, " ");[/CODE][/QUOTE]
That has no effect, use

[CODE]v = v.replace(/ [a-z]+=("")? /, " ");[/CODE]
Copy linkTweet thisAlerts:
@awsdertauthorOct 06.2010 — the v.replace thing i would have spotted on my own but thanks anyway

as for the non character changing, why is that?
Copy linkTweet thisAlerts:
@awsdertauthorOct 06.2010 — I finally fixed it and as far as I can see it is fully cross browser (as long as DOM lvl 1 is supported)
×

Success!

Help @awsdert 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.18,
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,
)...