Hello.
I have this code that is not able to capture this variable.
HTML, try 1:
<html>
<head>
<meta charset="utf-8" />
<script src="js.js"></script>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script></head><body><p><aonclick="funcao()">Clique aqui!</a></p>
</body>
</html>
JavaScript (with jQuery), try 1:
var link;
var testando="Testando essa <a href=\""+link+"\">variável</a> aqui.";
function funcao(){
link="http://www.google.com";
$('p').html(testando);
}
HTML, try 2:
<html>
<head>
<meta charset="utf-8" />
<script src="js.js"></script>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script></head><body><p><aonclick="funcao('www.google.com.br')">Clique aqui!</a></p>
</body>
</html>
JavaScript (with jQuery), try 2:
var link;
var testando="Testando essa <a href=\""+link+"\">variável</a> aqui.";
function funcao(link){
$('p').html(testando);
}
In either case, the variable "link" is received, with the value "undefined".
This is the initial form that works (but I'm optimizing):
Try 1 HTML;
JavaScript (with jQuery):
var link;
var testandoi="Testando essa <a href='";
var testandoii="'>variável</a> aqui.";
function funcao(link){
$('p').html(testandoi+link+testandoii);
}
I find it totally unnecessary to declare two variables for a single sentence.
If someone has a solution, thank you in advance.