I added text to an element with jQuery but the font doesn't match.
I used:
jQuery(document).ready(function(){
jQuery("i.fas.fa-search").text(" SEARCH");
How can I target just the text to change the font-family?
I added text to an element with jQuery but the font doesn't match.
I used:
jQuery(document).ready(function(){
jQuery("i.fas.fa-search").text(" SEARCH");
How can I target just the text to change the font-family?
Sure thing!
The i element only contains the icon; it can contain other text but leads to complications in my experience. To add text adjacent to the icon I'd recommend appending text to the icon's container element. So if you had:
<button id="button"><i class="fas fa-search"></i></button>
You'd use:
$("#button").append("<span>Search</span>");
This adds a span element after the search icon within the button element. If you're trying to accomplish something simple like a hover reveal you could even just put the span in there to begin with and reveal it with CSS properties to prevent having to add and remove it programatically, but adding it with JS will work if you just want to add it in once.
Try this code .
Create a class in your css:
.prjct-font{
font-family: 'your-font';
}
in Jquery:
jQuery(document).ready(function(){
jQuery("i.fas.fa-search").html('<span class="prjct-font"> SEARCH</span>');
});
Because of font-awesome you can change i Tag
font