Quantcast
Channel: User motagirl2 - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by motagirl2 for How do I make a menu that declares a variable within Javascript

$
0
0

If you can use jQuery, it's quite simple, just invoke a function that creates the variable (keep in mind that you will only be able to operate with that variable inside that function), or if you need it anywhere else, create the variable at global scope and just use the function to modify it.For exmample:HTML:

<a id="page1" onclick="makevar('hello word')">Home</a><a id="page2" href="">About us</a><a id="page3" href="">Services</a><a id="page4" href="">Partners</a><a id="page5" href="">Contact us</a>

Javascript:

var var1="";function makevar(varcontent){var1=varcontent;alert(var1);}

See both options working here https://jsfiddle.net/3Lyeo6kc/1/ and https://jsfiddle.net/3Lyeo6kc/2/


Viewing all articles
Browse latest Browse all 22

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>