Search code examples
jqueryhtmlcssstylesheetelement

HTML Elements in jQuery and CSS styling in jQuery


I am known to HTML and CSS. Now I am trying to learn jQuery. I want to know how to make a DIV in jQuery and then style it with CSS in jQuery?

I have searched alot on google but cant find any help there. I hope you can help me.

Everything from make a DIV and then styling it should only be done in jQuery. I dont want to use HTML at all.

Thanks


Solution

  • This sample attaches a div to the parent container, and adds some css styling to it.

    $(document).ready(function(){
      var theNewDiv = $("<div id='mydiv'>").appendTo("body");
      theNewDiv.css({"height": "100px", "width": "100px", "background-color":"blue"});
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>