This question already has answers here:
What are alternatives to document.write?
(11 answers)
Closed 3 years ago.
So guys, I made a little script to put in Tampermonkey for my presentations, but I have a problem.
What I want is to swap document.write(), but I don't know which function I could swap to replace it so that it leaves the code cleaner and more organized.
Besides document.write() is also not considered a good programming practice.
You could try to come up with your own function. But before taking any action, you need to think that there must be a injection into document body. You can try to use
document.body.appendChild()
and inside off that method, you can have some kind of html code.
Other than that you must generate a html document by using document.createDocumentFragment() or document.createElements().
Related
This question already has answers here:
Textarea that can do syntax highlighting on the fly?
(11 answers)
Closed 2 years ago.
I'm looking for textarea so I can write css code inside it. And have a good graphic appearance for displaying css code
As in the picture below:
There can be really one of two ways to do that: either you will implement it yourself OR use ready made libraries. Solutions like that exist in great variety and it could save you a lot of time to use one of following or find a similar one:
Edit Area
highlight.js
CodeMirror
This question already has answers here:
Do DOM tree elements with IDs become global properties?
(5 answers)
What is the difference between getElementById and simply using an element's ID as a variable?
(2 answers)
Closed 5 years ago.
So, I was coding in class when accidentally got to this point, when you set any ID in HTML5 a global variable is created at the same time, which can be used on the script aparently the same way we use getElementById().
for example:
<div id="identifier"></div>
can be accessed in the script like:
identifier.style.whatever
Can anyone explain me why I can't find any information about this? also, why isn't anyone using this when coding? is it bad to use this instead of getElementById?
This question already has answers here:
Lightweight alternative to jQuery for class / id selecting
(6 answers)
Closed 8 years ago.
I have this jQuery selector:
$('#stuffElements').find('[data-markerlayer="layer1"]');
I have a ton of selectors similar to this one, and I want to optimize my script as much as possible, as rewriting most selectors requires only minimal effort on my part.
Disregarding the discussion whether this is useful, is it possible to write the above selector out in pure JavaScript?
document.querySelectorAll('#stuffElements [data-markerlayer="layer1"]')
or to make it more efficient:
var holder = document.getElementById('#stuffElements'); // cache parent node
holder.querySelectorAll('[data-markerlayer="layer1"]'); // finds inside it
querySelectorAll doesn't work in IE7 if that bothers you.
This question already has answers here:
How can I reduce jQuery?
(7 answers)
Closed 1 year ago.
Is there a way to reduce jQuery to functions that I need.
In this case, I only want to use getJSON with the callback function. I don't need anything else of jQuery. Is there any way to cut this out?
Thanks,
Mike
You can do AJAX without jQuery. One explanation:
http://davekb.com/browse_programming_tips:easy_ajax:txt
Not really, there are a lot of dependencies, but modularity is planned.
As an aside, a getJSON() function isn't particularly hard to implement.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Why split the <script> tag when writing it with document.write()?
I don't really do Javascript programming and was hard to google this but have seen something like this in a couple of different places (by good developers):
document.writeln('<scr'+'ipt src="'+pcheck+'" type="text/javascript"></scr'+'ipt>');
With the split always between the r and the i. What does this achieve?
This is to prevent any script blockers from loading this script, because they cannot find the "script" word within the text.