Solved

Include css using javascript/jquery in html

Posted on 2016-10-20
1
90 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 57

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

717 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