Answer the question
In order to leave comments, you need to log in
Firefox. HTML5. JS element access by ID
There is a code
<!DOCTYPE html > <html><body> <div id='dv'></div> </body></html> <script> dv.innerHTML='hello'; </script>
Answer the question
In order to leave comments, you need to log in
I wrote a macro for VS.NET here to wrap elements in jQuery, bringing them into a normal "hello 90s" look. maybe it will be useful for someone too.
Private Sub Wrap(ByVal prefix, ByVal sufix)
Dim t As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
If t.Text.Length = 0 Then
t.WordLeft()
t.WordRight(True)
End If
t.Text = prefix & t.Text.Trim & sufix
End Sub
Public Sub Wrap_jQuery() ' hotkey Alt+J
'оборачиваем obj в $('#obj')
Wrap("$('#", "')")
End Sub
Public Sub Wrap_e() ' hotkey Alt+E
'в js скрипт: function $e(name) { return typeof (name) === 'string' ? document.getElementById(name) : name; }
Wrap("$e('", "')")
End Sub
can someone answer me why an element in FF cannot be accessed directly?
without comments about the validity of html5, etc.?
> I wanted to convert the site to HTML5
> accessing the DOM element through the window property
Instead of the “html” tag, write “html5”, then it will definitely work.
The script after /html is not valid. Therefore, it does not work in html5, only in quirksmode.
dv.innerHTML='hello';
The 90s are long gone.
If you have everything in this form, then yes, it will be difficult to switch to something modern (
Insert the script in the head tag or before closing the body.
getelementbyid.ru/
understandably. but not convenient... all browsers understand and FF is not
in VisualStudio through intellisense, you can quickly type object names, and now you have to wrap each element in a custom $e() or in jquery
Wow. To be honest, I thought so for a long time in all browsers ... No, this antiquity is still preserved. Wow.
Use
var dv = document.getElementById('dv');
yeah, stop downvoting me.
I realized my problem and closed the topic ...
in general, I completely agree with all the commentators who spoke above.
If you switch to modern technologies, then switch completely. Don't move - don't move.
If for some reason this is unrealistically important, then you can (although I highly recommend not) do this ugly hack:
var all = document.getElementsByTagName('*');
for (var i = all.length; i--;) if (all[i].id) {
document[all[i].id] = all[i];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question