如何将CSS与javascript一起使用

How to use CSS with javascript

本文关键字:一起 javascript CSS      更新时间:2023-09-26

我正在使用PHP从我的数据库中返回数据,然后使用javascript允许该人添加它。而且我无法使div更改其背景颜色并添加边框等。

<div class="selectedStuff"></div>
<script type="text/javascript">
   $('#addButton').on('click', function( event ) {
        $('.selectedStuff').append($('#search_term').val() + '<br>'); 
   });          
</script>
<style type="text/css">
   .selectedStuff{
       background-color: yellow;
       margin-top: 50px;
   }
</style>

在这件事上的任何帮助都会很棒

$('#addButton').on('click', function( event ) {
                var searchedValue = $('#search_term').val(); 
                var divHolder = $('.selectedStuff'); 
                divHolder.append(searchedValue + '<br>').css({
                    'background-color': 'yellow',
                    'margin-top': '50px'
               }); 
           });