Reputation: 805
I have a javascript file to which I send a parameter
<script lang="en" src="/test/load.js" ></script>
In the file I have script similar to this:
! function()
{ some code
var lag = ( script.getAttribute( 'lang' ) == null || script.getAttribute( 'lang' ) == '' ) ? exit : script.getAttribute( 'lang' );
The idea is that I do not want to execute the code after the one quoted above in case that parameter 'lang' is missing or is an empty string. How can I do that, I tried using
exit
or
break
but they do not work for me.
Upvotes: 2
Views: 12342
Reputation: 101730
I think the main problem is that you're trying to use the conditional operator as a sloppy alternative to an if
statement.
Just use an if
statement, with return
:
var lang = script.getAttribute('lang');
if (!lang) {
return;
}
Upvotes: 6
Reputation: 334
Use this to stop script
return false;
Upvotes: 1