Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript span tag inserted as undefined using DOM method

thisisjek

New Coder
I have been using DOM methods to insert html elements routinely and dependably
but I am now working on a project that is supposed to replace a textarea element
with a span tag that contains the content entered into the textarea.

JavaScript:
case 'TEXTAREA':
var holdOver = e.target.value;
var holdOverId = e.target.id.split('-');
var keyStr = holdOverId[0];
var seq = holdOverId[1];
var parent = e.target.parentNode;
e.target.parentNode.removeChild(e.target);
parent.appendChild(mkElem({'type':"span", 'props':{'id':keyStr+'-0'}})); //<<<<<<<
hostList[keyStr+'-0'].appendChild(textNode(holdOver)); // <<<<<<
document.getElementById(keyStr+'-group-'+seq).disabled = false;
break;

this is what is inserted into the document by the htmlElement.appendChild method.
HTML:
<undefined id="WE-0">x</undefined>

The span tag would be a child node of a pre tag.

The point is to be able to convert the span tag back to a textarea element for editing
the text. That is the purpose of the span tag: to get text contained in it.

Is there some recent security problem with inserting span tags using DOM methods?

I am working on MacOS Sequoia and Firefox 133.x. But the same issue shows up in Safari on the
same system.
 
Last edited by a moderator:
Solution
Hello, Its me again.
I found MY mistake and fixed the problem.
It was a syntax issue. The mkElem function I wrote
needed the first argument member to be 'elem':'span'
instead of 'type':'span'.
Thanks for time and attention to anyone who read this
JK
Hello, Its me again.
I found MY mistake and fixed the problem.
It was a syntax issue. The mkElem function I wrote
needed the first argument member to be 'elem':'span'
instead of 'type':'span'.
Thanks for time and attention to anyone who read this
JK
 
Last edited:
Solution
Hello, Its me again.
I found MY mistake and fixed the problem.
It was a syntax issue. The mkElem function I wrote
needed the first argument member to be 'elem':'span'
instead of 'type':'span'.
Thanks for time and attention to anyone who read this
JK
Happy you got this sorted and thank you for sharing the solution with us 🙂
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom