Creating link in JavaScript, and integrating it into createTextNode() -


i'm looking integrate link created text node, comes text (title), not link. how fix this?

code in function:

function createmessage() {    var = document.createelement('a');    var linktext = document.createtextnode("http://www.example.com");    a.title = "http://www.example.com";    a.href = "http://www.example.com";    var message2 = document.createelement("p");    var message2text = document.createtextnode("website: " + + ".");    message2.appendchild(message2text);    var olelem = document.getelementbyid("display");    var old = document.getelementbyid("display");    var display = old.parentnode;    return display.replacechild(message2, olelem); } 

problem here:

var message2text = document.createtextnode("website: " + + "."); // ---------------------------------------------------^^^^^^^ 

you can't append dom element string , useful result.

it's hard figure out you're trying in code, create paragraph containing link, simplest way innerhtml:

var p = document.createelement('p'); p.innerhtml = 'website: <a href="http://example.com" title="http://example.com">http://example.com</a>.'; 

...and append/insert desired.

but if want in bits , pieces, it's:

var = document.createelement('a'); a.href = "http://example.com"; a.title = "http://example.com"; a.appendchild(document.createtextnode("http://example.com")); var p = document.createelement('p'); p.appendchild(document.createtextnode("website: ")); p.appendchild(a); p.appendchild(document.createtextnode(".")); 

...and append/insert desired. note how had create 3 separate text nodes: text before link, text within link, , text after link.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -