I am baffled by this. I'm working with a WordPress website and I have 2 simple Javascript alert functions. I'm using one of them in the onclick of an image to make sure the script works. All is well if I don't have any empty lines in my script, but if I add any empty lines, nothing works (see the code below for an example).
Javascript and PHP both ignore white space. The only one I'm not sure about is HTML. There's not really much out there on how HTML treats white-space (although I feel like I read somewhere that it ignores it if it's not in an element). Is HTML white-space sensitive (other than in elements)? If not, why would empty lines mess up my scripts? I guess it's not that big of a deal because I can just remove the empty lines, but I would like to make my code neater and find out what's causing this.
Here's an example of my code:
// This works fine because there's no empty lines
<script type='text/javascript'>
function showAlert() {
alert("The first showAlert function works!");
}
function showAnotherAlert("The other alert is working!");
</script>
// This won't do anything because of the empty lines between the functions
<script type='text/javascript'>
function showAlert() {
alert("The first showAlert function works!");
}
function showAnotherAlert() {
alert("The second alert is working!");
}
</script>
Does anyone have any insight on this?
tags in the place of where your line breaks are. Unfortunately i haven't found a solution yet so thats why im not answering.
– dev Apr 27 '13 at 07:39