Lestah
Lestah

Reputation: 53

how can i append a list item

$("ul").append("<li><a href=""><?php echo $this->session->userdata('username'); ?></a></li>");

This is giving me an error on my console it says Uncaught SyntaxError: missing ) after argument list

Upvotes: 0

Views: 46

Answers (2)

Andreas Vitzthum
Andreas Vitzthum

Reputation: 11

I would write it this way

$("ul").append("<li><a href=\" \"><?php echo $this->session->userdata('username'); ?></a></li>");

or this way

$("ul").append("<li><a href=''><?php echo $this->session->userdata('username'); ?></a></li>");

Upvotes: 1

N. Ivanov
N. Ivanov

Reputation: 1823

Change the "" of the href to '' otherwise they close your string. Here is a working example:

$(function() {
  $("ul").append("<li><a href=''><?php echo $this->session->userdata('username'); ?></a></li>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<ul></ul>

Hope this helps!

Upvotes: 1

Related Questions