我想創建一個新樣式,而不僅僅是改變元素的樣式屬性。下面是一些示例代碼來演示該問題:在jQuery中創建一個新的(permenant)CSS樣式
//Create 1st element
var element1 = $('<div />').text('element1').addClass('blue');
$('body').append(element1);
//Set some css for all elements with the blue class
$('.blue').css('background-color', 'blue');
//Create 2nd element, it won't have the css applied because it wasn't around when the css was set
var element2 = $('<div />').text('element2').addClass('blue');
$('body').append(element2);
在第二個元素上面的代碼不具有相同的風格爲1日。我想要的是能夠爲所有將來的元素在className上設置css。
可能重複[使用JQuery添加到css類](http:// stackov erflow.com/questions/5877440/add-to-a-css-class-using-jquery) –