admin管理员组

文章数量:1323317

I have this div:

<div id="libraryDisplay">asdf</div>

and this code:

$('#libraryDisplay').val(booksList);

and booksList is a string. It's still displaying "asdf". Any suggestions?

I have this div:

<div id="libraryDisplay">asdf</div>

and this code:

$('#libraryDisplay').val(booksList);

and booksList is a string. It's still displaying "asdf". Any suggestions?

Share asked Jan 22, 2014 at 22:04 ionox0ionox0 1,1112 gold badges14 silver badges21 bronze badges 1
  • div elements don't have a value. – Kevin B Commented Jan 22, 2014 at 22:15
Add a ment  | 

2 Answers 2

Reset to default 6

val is for form elements. If you're trying to set the text of the <div>, use text instead:

$('#libraryDisplay').text(booksList);

If booksList is actually an HTML fragment (and you're reasonably sure it's ing from a safe source and doesn't have the potential to corrupt your page) use html:

$('#libraryDisplay').html(booksList);

Try

$('#libraryDisplay').html(booksList);

本文标签: javascriptChange value of div using jquery val() not workingStack Overflow