travisowens Posted January 30, 2007 Posted January 30, 2007 (edited) . ...........RESOLVED (see next post) . I'm looking into somebody's Javascript code and I came across this syntax, I have no idea what the if/with line means and Google isn't helping. BTW, this is part of a web control that puts a HELP link on the top right of pages. <div id="HelpTopRight" class="HelpTopRight" style="white-space:nowrap;"> <xsp:HelpLink ID="lnk" runat="server" /> </div> <script type="text/javascript" language="javascript"> var x=document.getElementById('HelpTopRight') [b]if(x)with(x)[/b] { style.setExpression('left',document.body.clientWidth-60) } </script> Edited January 30, 2007 by travisowens Quote Experience is something you don't get until just after the moment you needed it
travisowens Posted January 30, 2007 Author Posted January 30, 2007 (edited) I wouldn't have questioned this at all if I had seen a more formal syntax, such as if(x) { with(x) { style.setExpression('left',document.body.clientWidth-60) } } I'm outright shocked that with() works outside the brackets. Edited January 30, 2007 by travisowens Quote Experience is something you don't get until just after the moment you needed it
MrPaul Posted January 31, 2007 Posted January 31, 2007 Brackets Rather than it being a case of with() being outside the brackets, it is a case of the brackets belonging to the with block rather than the if block. Any control structure can be used without brackets - operating on a single statement. For example: if (x) doThis(); However, that single statement can be another control structure with its own block of code (as in this case). :) Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.