Search code examples
javascriptjqueryinternet-explorerappendappendchild

Jquery .append() not working in Internet Explorer 11


I am trying to execute below code. It's working fine with chrome and firefox but giving me issue with IE 11.

Error message in IE is: SCRIPT1002: Syntax error

Code is:

$("div#formFields").append(
                        $("<label/>").text(formField['Data'][i]['field_label']),
                        $("<input/>", {
                            type: text,
                            id: 'selectTest',
                            name: 'selectTest',
                            required: "true",
                        }),
                    );

<div id="formFields" >
</div>

Please help.


Solution

  • Remove the last comma inside append . See my code below

    <body  id="banner">
    <div id="formFields" ></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> 
    <script type="text/javascript">
            jQuery(document).ready(function($){
        
        $("#formFields").append(
                        $("<label/>").text("Texts"),
                        $("<input/>", {
                            type: "Texts",
                            id: 'selectTest',
                            name: 'selectTest',
                            required: "true",
                        })//Remove comma from here, 
                        //Comma added at the end will cause syntax error in IE
                    );
        
        
        });
    
        </script>
    </body>