What does the Semi-Colon do in our code?
-
A question for the HTML experts…
I know that codes follow logically as do the syntax and symbol usage…
when doing references on the web for code, simple example such “font-size” or “font Family” inside “div” “p” or “span” ( I have lapse in memory and have to look things up) sometimes a semicolon “;” is used and sometimes it is not. It seems I need the semicolon here for at wordpress.com for certain tags.
Since I need this to make sense for me, what does the
;mean or do in a tag? or what is its function?
thank you.
The blog I need help with is: (visible only to logged in users)
-
You will always need to use semicolons to separate attributes no matter if it’s here on wp.com or any site.
Now, the only time you will see semicolon inside a HTML tag is when you use the “style” attribute or events (e. g. onclick) in which javascript (which you cannot use here on wp.com) would be used, for example:
<a href="#" onclick="FunctionName(); return false;">do something</a>In a “style” attribute you would see something like this:
<div style="background: #ddd; border: solid 1px #999; color: #000;">some text here</div>In some cases you would see this:
<div style="background: #ddd; border: solid 1px #999; color: #000">some text here</div>See the difference? In case you don’t, in my second example the LAST property (color: #000) does not have a semicolon. You can leave it out on the _last_ rule of your styling. The same could have been done on the event attribute of my first example:
<a href="#" onclick="FunctionName(); return false">do something</a>“return: false” has no semicolon.
Although you can leave the last semicolon out, I always include it.
So, basically, the semicolon is a command delimiter so whenever the code is read, the parser (in this case the browser engine) will understand your commands and what to do next. Hope this makes sense?
-
You will always need to use semicolons to separate attributes no matter if it’s here on wp.com or any site.
Sorry, that should read “to separate properties” and properties are those inside the “style” attribute.
-
Yes it does make sense…
I will often see a case where one property is an attribute and it ends with the “;”
even though its not necessary, with just one property its used in good form.So the Semicolon is a properties separator.
Thank you, that was very helpful.
- The topic ‘What does the Semi-Colon do in our code?’ is closed to new replies.