开发者

Can't set div's content with Jquery

$('#messages').html('<p>Test</p>');

<div id="开发者_Python百科messages" style="height:520px; list-style: none; border: 1px solid black;" ></div>

For some reason this JQuery isn't working. Why?


yep, all of above. By the way: are you aware of this syntax:

$('<p>')
    .text('test')
    .addClass('ui-paragraph')
    .appendTo('#messages');

i find it more precise & powerful than the html method in some cases..


Should work, providing of course that you have a proper link to the jquery library, of course. -Check the path)


This does look like valid code, especially when checking out Marks Fiddle.

Although the major difference between the fiddle and your code is the absensce of

$(function() { //script here });

or something like it.

I also imagine the the jquery is either external or inserted between tags.

I tend to do two things 1. keep my scripts at the end of the page and wrap $(function() { //script here }); around my code. This maybe the problem here. It if the script is executed before the page loads their is no #message to append to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜