Solved

Include css using javascript/jquery in html

Posted on 2016-10-20
1
49 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 51

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now