I'am trying to insert a JavaScript object with the help of JQuery into a HTML-element like that:
var selectList = document.createElement("select");
//added some properties ..
//trying insert after a specific HTML tag
var selectedListValue=$(selectList) ;
$( "<tr><td>"+selectedListValue+"</td></tr>" ).insertAfter("#EFAForm_Klein div table tbody tr:last-child()");
I'am getting something like this, if I only insert "selectList":
"object HTMLSelectElement"
or this, if I use "$(selectList)":
"[object Object]"
Do I need to convert my JS-Object for JQuery ?
Ty for helping.
The problem is selectedListValue
is an jQuery object which when used in string concatenation results in [object Object]
. In the same way selectList
is an HTMLElement object whose toString() returns object HTMLSelectElement
What you need to do is to append the tr
then find the td
inside it and append the selectList
to it
$("<tr><td></td></tr>").insertAfter("#EFAForm_Klein div table tbody tr:last-child").find('td').append(selectList);
you should omit the ()
:
.insertAfter("#EFAForm_Klein div table tbody tr:last");
or a better one:
$("#EFAForm_Klein tr").filter(':last')
.after('<tr><td></td></tr>').find('td')
.append(selectedListValue);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.