Skip to main content
added 373 characters in body
Source Link
clickbait
  • 3k
  • 1
  • 17
  • 27

RELATED: Allow us to choose a doctype for Stack Snippets


I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Does the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to put that manually?


Follow-Up Question

According to the answer, code snippets take care of the heavy lifting. What if you want to put stuff in the <head>? Will the wrapper elements be duplicated, or will the snippets accommodate for it?

For instance, someone who wants to show differences between character encodings has to use a <meta> tag in the <head>

RELATED: Allow us to choose a doctype for Stack Snippets


I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Does the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to put that manually?

RELATED: Allow us to choose a doctype for Stack Snippets


I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Does the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to put that manually?


Follow-Up Question

According to the answer, code snippets take care of the heavy lifting. What if you want to put stuff in the <head>? Will the wrapper elements be duplicated, or will the snippets accommodate for it?

For instance, someone who wants to show differences between character encodings has to use a <meta> tag in the <head>

added 115 characters in body
Source Link
clickbait
  • 3k
  • 1
  • 17
  • 27

RELATED: Allow us to choose a doctype for Stack Snippets


I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Does the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to put that manually?

I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Does the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to put that manually?

RELATED: Allow us to choose a doctype for Stack Snippets


I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Does the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to put that manually?

added 236 characters in body; edited title
Source Link
clickbait
  • 3k
  • 1
  • 17
  • 27

Are <html>, <head>, <body>, etc. required Do I need to put onloads and main elements in code snippets?

I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Question: doesDoes the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to writeput that manually?

Are <html>, <head>, <body>, etc. required in code snippets?

I can put this in a code snippet:

<div id="box">Hello, World!</div>

I can also do this:

<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Question: does the code snippet system automatically fill in the <html>, <head>, <body>, etc. or are you supposed to write that?

Do I need to put onloads and main elements in code snippets?

I can put this in a code snippet:

$("#box").css("color", "red");
<div id="box">Hello, World!</div>

I can also do this:

$(document).ready(() => {
    $("#box").css("color", "red");
});
<!doctype html>
<html>
    <head></head>
    <body>
         <div id="box">Hello, World!</div>
    </body>
</html>

Does the code snippet system automatically fill in the <html>, <head>, <body>, etc. and start executing JS when the page has finished loading, or are you supposed to put that manually?

Rollback to Revision 3
Source Link
Martijn Pieters Mod
  • 1.1m
  • 96
  • 930
  • 755
Loading
added 10 characters in body
Source Link
clickbait
  • 3k
  • 1
  • 17
  • 27
Loading
added 289 characters in body; edited title
Source Link
clickbait
  • 3k
  • 1
  • 17
  • 27
Loading
fixed formatting
Source Link
Mureinik
  • 309.6k
  • 7
  • 76
  • 95
Loading
added 289 characters in body; edited title
Source Link
clickbait
  • 3k
  • 1
  • 17
  • 27
Loading
Post Closed as "Duplicate" by πάντα ῥεῖ, Martijn Pieters support
Source Link
clickbait
  • 3k
  • 1
  • 17
  • 27
Loading