I can't figure this one out...
Could someone please help me en explain how it works to?
Goal:
Adding a variable to a hard-coded URL, and put the new string into a href
Example:
var x = "1000";
var y = "http://www.google.com"
var result = y + x;
<a href="! the value of result !">click here...</a>
Edit i'm sorry i meant y + x ofcourse...
Given this HTML code:
<a href="" target="_blank">click here...</a>
You would need this bit of js code:
(working example http://jsfiddle.net/QUEZL)
var x = "http://www.google.com/"
var y = "#q=test";
var result = x + y;
$('a').attr('href', result);
Try
$("a").attr("href", result)
HREF is an attribute so you can access it via .attr()
var x = "1000";
var y = "http://www.google.com/"
var result = y + x;
$('a').attr({'href':result});
JavaScript:
document.getElementsByTagName('a')[0].href = result ;
jQuery:
$("a").attr("href", result)
For me, all the above approaches were replacing the variable with the latest value of the variable as it was referred in a loop.
Solution:
$.each(statusForUI, function( key, value ) {
x = "http://192.168.10.100:8888/workflow/" + key;
$('.listTable').append(
'<tr><td>' +
'<a href="' + x + '"> env_name </a>' +
key +
'</ td></tr>'
);
});