如何在JQuery中操作DOM元素 [英] How do I manipulate a DOM element in JQuery

查看:81
本文介绍了如何在JQuery中操作DOM元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Jquery更改标题的颜色。以下是我的代码,我看不出我的错误在哪里。请任何人都可以帮助我???我刚刚在udemy完成了一个教程,我正在尝试做一些额外的问题。





 <  !DOCTYPE     html  >  
< html >
< head >
< < span class =code-leadattribute> title > 使用Jquery < < span class =code-leadattribute> / title >
< script src = // ajax.googleapis.com/ajax/libs/jquery/1.11。 1 / jquery.min.js > < / script >

< script src = // ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js > < / script >



< 样式 type = text / css >
.red {
color:red;
background-color:blue;
}

< / style >

< / head >
< body >
< h1 > kakjdnjkasn kashdask ajkshdask jdhsajkd hasjkd hsajdkhsajdk asd < / h1 >
< h1 id = flavio > 这是一个头脑ng < / h1 >
< p id = myParagraph > kjshdkas dhaksjdh ajks hdasjkdhas jkdh < / p >

< script >
// $('h1').addClass('red');

$('#flavio')。css({'background-color':red});

$(#myParagraph)。css({background-color:black,color:white});
< / script >


< / body >
< / html >

解决方案

('h1')。addClass('red') ;


('#flavio')。css({'background-color':red});


(#myParagraph)。 css({background-color:black,color:white});
< / script >


< / body >
< / html >


I would like to change the color of my headers using Jquery. The following is my code, I can not see where my error is. Please can anyone help me??? I just finished a tutorial in udemy, and I am trying to do some extra problems.


<!DOCTYPE html>
<html>
<head>
<title>Working with Jquery</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>



<style type="text/css">
.red{
    color:red;
    background-color: blue;
}

</style>

</head>
<body>
    <h1>kakjdnjkasn kashdask ajkshdask jdhsajkd hasjkd hsajdkhsajdk asd</h1>
<h1 id="flavio">This is a heading</h1>
<p id="myParagraph">kjshdkas dhaksjdh ajks hdasjkdhas jkdh</p>

<script>
//$('h1').addClass('red');

$('#flavio').css({'background-color': red});

    $("#myParagraph").css({"background-color": "black", "color": "white"});
</script>


</body>
</html>

解决方案

('h1').addClass('red');


('#flavio').css({'background-color': red});


("#myParagraph").css({"background-color": "black", "color": "white"}); </script> </body> </html>


这篇关于如何在JQuery中操作DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆