Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Добавление нового класса (https://javascript.ru/forum/jquery/30722-dobavlenie-novogo-klassa.html)

Heidel 13.08.2012 16:12

Добавление нового класса
 
Если я пропишу
<head>

<script src=\"/css/lib/jquery.min.js\"></script>
<script src=\"/css/lib/jquery.jcarousel.js\"></script>

<style type=\"text/css\">
.nullPadding {
margin-top: 0px; 
margin-bottom: 0px;
}
</style>

<script type=\"text/javascript\">

jQuery(document).ready(
    jQuery('p').addClass('nullPadding'));

</script>
</head>

(это, разумеется, не всё, что есть в хэде; двойные кавычки экранированы для cms)
это правильный код?
Вносимые изменения будут отображаться в коде страницы?

И еще вопрос, можно как-то прописать, чтобы добавлялся не класс, а в тег <p> напрямую вносились стили?
<p style='margin-top: 0px; margin-bottom: 0px;'>

?

Deff 13.08.2012 16:31

<script type=\"text/javascript\">

$(document).ready(function(){
    jQuery('p').addClass('nullPadding')
});
</script>

Serg_pnz 13.08.2012 16:32

http://jquery.page2page.ru/index.php...81%D1%81%D0%B0

http://jquery.page2page.ru/index.php...%B0_%D1%81_CSS

Heidel 14.08.2012 09:57

То есть так, верно?
<script type=\"text/javascript\">
    jQuery(document).ready(function(){
        jQuery('div.article p').css('margin-top: 0px; margin-bottom: 0px; padding: 0px;')
</script>

Deff 14.08.2012 10:09

<script type=\"text/javascript\">
jQuery(document).ready(function(){
        jQuery('div.article p').css({
		'margin-top'   : '0px',
		'margin-bottom': '0px',
		'padding'      : '0px;' //Последний без запятой
	});
});
</script>

Heidel 14.08.2012 10:48

Точка с запятой у последнего пункта таки лишняя.
Спасибо!


Часовой пояс GMT +3, время: 01:15.