My solution, maybe too complicated, one path for opera which is pretty
good and with good performance, the path for internet explorer which
is complicated, and for my testing it is stable, hope it can make $ to
be much more cross-browser, I believe the js framework should fix the
browser's bug, the path for ie won't work on opera and of course the
path for opera won't work on ie, complicated.
function $(element) {
if (arguments.length > 1) {
for (var i = 0, elements = [], length = arguments.length; i <
length; i++)
elements.push($(arguments[i]));
return elements;
}
if (typeof element == 'string')
{
var id=element;
element = document.getElementById(element);
var tmp=[];
var t=document.getElementById(id);
if (Prototype.Browser.IE)
{
while(t!=null && t.id!=id)
{
var e=t.outerHTML;
t.outerHTML=t.outerHTML.indexOf('name="')!=-1?
t.outerHTML.replace('name="'+t.name+'"','name="'+t.name
+'_tmp_"'):t.outerHTML.replace('name='+t.name,'name='+t.name+'_tmp_')
tmp.push([document.getElementById(t.name+"_tmp_"),e])
t=document.getElementById(id);
}
tmp.each(function(node){node[0].outerHTML=node[1]});
}
else if(Prototype.Browser.Opera)
{
while(t!=null && t.id!=id)
{
tmp.push([t,t.name])
t.name+="_tmp_";
t=document.getElementById(id);
}
tmp.each(function(node){node[0].name=node[1]});
}
element=t;
}
return Element.extend(element);
}
On Jun 18, 3:01 pm, "Mislav Marohnić" <[EMAIL PROTECTED]>
wrote:
> On 6/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
>
> > <input type="text" value="this should be returned" name="test" id="www" />
> > <input type="text" value="this should not be returned ff2.0 bug not
> > appeared in ff3.0 a5" name="test" id="www" />
>
> This is not valid HTML. It has 2 different elements with the same ID, in
> which you get unexpected behavior with getElementById.
>
> 1.In ie the only way to change a input element's attribute "name" is
>
> > to change outerHTML?
>
> Yes, you are basically re-writing the element. That is never smart.
>
> 3.Is there a regular expression to get out the name attribute from
>
> > these two strings '<input type=button value="aaa lll" name=lll />'
> > and'<input type=button value="aaa lll" name="lll l" />' one name with
> > "" one without, and the method to modify it. Thanks
>
> Of course there is, but there is no sense in making it. I think you now need
> to stop trying to solve this with outerHTML because it's just plain wrong
> and you'll just have problems down the line.
>
> There are only 3 possible options we're facing:
>
> 1. Don't change the $ function, leave everything as-is;
> 2. Fix the issue in $ by using $$('*[id=foo]');
> 3. Don't fix the issue, throw error instead.
>
> I don't believe we need to discuss anything else but these.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---