0

I'm using PHP to return data from my database and then using javascript to allow the person to add it. And I can't make a div change its background color and add borders etc.

<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>

Any help on this matter would be great

1
  • Use the .css() methods on your divHolder Commented Mar 12, 2016 at 12:12

1 Answer 1

2
$('#addButton').on('click', function( event ) {
                var searchedValue = $('#search_term').val(); 
                var divHolder = $('.selectedStuff'); 
                divHolder.append(searchedValue + '<br>').css({
                    'background-color': 'yellow',
                    'margin-top': '50px'
               }); 
           });
Sign up to request clarification or add additional context in comments.

2 Comments

Ye just spotted it :0 perfect x
Why would you replace perfectly good CSS with the old-fashioned jQuery approach of applying styles directly to elements? Why doesn't the OP's CSS work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.