Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Include css using javascript/jquery in html

Posted on 2016-10-20
1
Medium Priority
?
97 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 59

Accepted Solution

by:
Julian Hansen earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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 …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

604 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