webmaniac schreef:
On Nov 12, 12:40 pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
>webmaniac schreef:
>>Hi,
I am creating a table dynamically in javascript.
All is fine but when I try to put any ahref link on the cell its not
taking it. I am doing like that.
var rowHead1 = document.createElement('TR');
var CellHead1 = document.createElement('TD');
var text1 = "<a href=http://www.google.com>" + someVariable + "</a>
var cellHeadText1 = document.createTextNode(text1);
CellHead1.appendChild(cellHeadText1);
But somehow when I run this example.
It shows like that in Table cell.
<a href=http://www.google.com>abc</a>
Its not converting it into a Link.
Any Idea, what's going wrong here.
Hi,
Not sure, but shouldn't you at least quote the hyperlink properly?
Like this:
var text1 = "<a href='http://www.google.com'>" + someVariable + "</a>";
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
I tried that too, but it still dont work.
I dont know, where I am getting wrong.
Ahum, sorry.
You know this feeling you are knew how something worked but totally
cannot retieve it?
I just had that great experience again, but a little googling helped.
You need to create the hyperlink element first ('a') and append that.
this is the trick:
var aElem = document.createElement('a');
Here is a sample from:
http://acsummer.wordpress.com/2007/1...g-a-hyperlink/
function appendLink()
{
//Get the element that we want to append to
var divEl = document.getElementById('link_div');
//Create the new <a>
var aElem = document.createElement('a');
aElem.href="http://www.google.com";
//Create a text node to hold the text of the <a>
var aElemTN = document.createTextNode('link to Google.com');
//Append the <atext node to the <aelement
aElem.appendChild(aElemTN);
//Append the new link to the existing <div>
divEl.appendChild(aElem);
}
That should help. :P
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare