Solved

Include css using javascript/jquery in html

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

739 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