Search code examples
jquerynode.jspug

Pass 2 values into 2 attributes in jQuery


I have a problem with Node.js and Pug engine template. In PHP(HTML) I can pass two values into 2 attributes easy: For example (I pass row[id] into button's id and class attributes):

 <?php  
 while($row = mysqli_fetch_array($result)) {  
 ?>  
 <tr>  
 <td><?php echo $row["name"]; ?></td>  
 <td><input type="button" name="view" value="View" id="<?php echo 
 $row["id"]; ?>" class="<?php echo $row["id"]; ?>" /></td>
 </tr>  
 <?php  
 }  
 ?>  

How can I pass row.id into class attribute in input type = 'button' in Node.js(Pug)? In example below Pug doesn't define the 'class' attribute. Example

$.ajax({
                    type: "POST",
                    //contentType: "application/json",
                    url: "select_marks",
                    //data: formData,   //JSON.stringify(formData),
                    dataType: 'json',
                    success: function (data) {
                        $.each(data, function (i, row) {
                            $('.content').append(
                                 "<input type ='button' id=" + row.id + "class=" + row.id + ">"
                            );

                        });
                    }
                });


Solution

  • Its probleme of quotes don't forget you have '' in your html attributes

    If you get good data in your row I just write like that

    $('.content').append(
       "<input type ='button' id='" + row.id + "'class='" + row.id + "'/>"
    );
    

    https://jsfiddle.net/j0z5Lxc4/3/