开发者

How do I create series of div and make them accessible for jquery to modify them after a while?

开发者 https://www.devze.com 2022-12-13 19:45 出处:网络
I want to create some DIV from javascript. I don\'t know how many I will need to create, but I will need to change the 开发者_运维问答back-color of it after a while.

I want to create some DIV from javascript. I don't know how many I will need to create, but I will need to change the 开发者_运维问答back-color of it after a while.

I'm using jQuery in my project. So if it's easier the solution can use jQuery.


var $myDiv = $('<div />');

This will create a div inside the variable $myDiv.

You can change any property of it later on, and you can even add it to your page, like:

$myDiv.css('background-color', '#FFF').appendTo('#anotherDiv');


Give them a class name that you can later refer to.


Give them a class name, and then refer to it in jQuery like so:

<div class="something">Hello</div>
<div class="something">Hi</div>

<script type="text/javascript">
$(document).ready(function(){
  $('div.something').css('background-color', 'white'); // Or whatever
});
</script>
0

精彩评论

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