Solved

Include css using javascript/jquery in html

Posted on 2016-10-20
1
82 Views
Last Modified: 2016-10-25
Hi,
I am creating a search filter...in javascript library..
User will have an html element like <div id="filter/>

And pass the filter to my library...
My lib will replace this element with the html of the search filter....And my lib will also include js code required to interact with this search filter...

Here is the code as of now :
var html = '<div class="ring-js-filter"> \
                <input type="text" class="ring-js-input" value="..." placeholder="Search.." autocomplete="off"> \
                <div class="ring-js-close-icon" id="ring-js-fliterclose"></div> \
                <div class="ring-js-drop-down"> \
                </div>  \
              </div>';
   $(id).replaceWith(html);
   filter.setupSearchFilter();

Open in new window

This code is inside my lib and also include js code to interact with it...
How do i include css to style this.
One way proabably i coudl make a css file and bundle it with my javascript file .
Any alternative way ??

Thanks
0
Comment
Question by:Rohit Bajaj
1 Comment
 
LVL 56

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41853366
styling can be done like so
$('.ring-js-filter input').css ({
  color: 'blue',
  background: 'white',
  fontSize: '20px',
  borderRadius: '10px'
});

Open in new window

Note the selectors with '-' hyphens are camel cased with no hyphen

Do the same for any other styles you want on sub-elements.

Edit
Code shown in context with original source
var html = '<div class="ring-js-filter"> \
    <input type="text" class="ring-js-input" value="..." placeholder="Search.." autocomplete="off"> \
    <div class="ring-js-close-icon" id="ring-js-fliterclose"></div> \
    <div class="ring-js-drop-down"> \
    </div>  \
    </div>';
$(id).replaceWith(html);
$('.ring-js-filter input').css ({
  color: 'blue',
  background: 'white',
  fontSize: '20px',
  borderRadius: '10px'
});
filter.setupSearchFilter();

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question