Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<html>
<head><script type='text/javascript'>
$(window).load(function(){
   $("body").click(function(){
    var s = window.getSelection();
        s.modify('extend','backward','word');
        var b = s.toString();
       s.modify('extend','forward','word');
        var a = s.toString();
s.modify('move','forward','character');
var z=b+a;
z= z.trim();
aler(z); //for appear alert that word on click him
//now suppose we type here a new variable
var variable = "Hellow"; //i need it to move out of that function
});
});
var variable2 = variable;
alert(variable2);
</script>
</head>
<body>
<h3>Hellow world</h3>
</body>
</html>

Posted

1 solution

You can declare that as a global variable and then assign any value inside the function and then assign the same to other rather than assigning to other cars better use the global var value at places you want to.
Thanks
Post back your comments if any queries.
 
Share this answer
 
Comments
Amir khan gopang 20-Oct-14 17:52pm    
its not work when i Declear a globalvariable. Tell me any other solution to move a variable frrom function to outside.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900