Swap bootstrap text class for a google material icons
thank you all for the help...i got it to work using the following:
JAVASCRIPT
updateFavorites(id){
if($(this).find('#staricon'+id)){
if($('#staricon'+id).hasClass('star-color')) {
$('#staricon'+id).removeClass('star-color');
}
else {
$('#staricon'+id).addClass('star-color');
}
}
}
HTML:
<a class=" stats pull-right " href="javacript:void" ><span id="staricon' . $story_id .'" onclick="updateFavorites(' . $story_id . ')"><i class=" material-icons " title="Favorite" >star</i></span></a>
How to host material icons offline?
Method 2. Self hosting Developer Guide
Download the latest release from github (assets: zip file), unzip, and copy the font folder, containing the material design icons files, into your local project -- https://github.com/google/material-design-icons/releases
You only need to use the font folder from the archive: it contains the icons fonts in the different formats (for multiple browser support) and boilerplate css.
- Replace the source in the url attribute of
@font-face
, with the relative path to the iconfont folder in your local project, (where the font files are located) eg.url("iconfont/MaterialIcons-Regular.ttf")
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(iconfont/MaterialIcons-Regular.eot); /* For IE6-8 */
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(iconfont/MaterialIcons-Regular.woff2) format('woff2'),
url(iconfont/MaterialIcons-Regular.woff) format('woff'),
url(iconfont/MaterialIcons-Regular.ttf) format('truetype');
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
<i class="material-icons">face</i>
NPM / Bower Packages
Google officially has a Bower and NPM dependency option -- follow Material Icons Guide 1
Using bower : bower install material-design-icons --save
Using NPM : npm install material-design-icons --save
Material Icons : Alternatively look into Material design icon font and CSS framework for self hosting the icons, from @marella's https://marella.me/material-icons/
Note
It seems google has the project on low maintenance mode. The last
release was, at time of writing, 3 years ago!There are several issues on GitHub regarding this, but I'd like to
refer to @cyberalien comment on the issueIs this project actively maintained? #951
where it refers several community projects that
forked and continue maintaining material icons.
How can i change a text of a button without changing it's icon
.innerText
is a sort of "safe"* way to access a node's innerHTML
, which in your case includes both the Pause
-text, as well as the <i.../>
tag.
A way to solve this is to add a span
to hold the text. span
s don't do anything (as they are inline elements and are by default formatted/shown as a simple text element), but they help by making the text node selectable by document.querySelector
!
Example:
var playing = true
window.addEventListener("load", () => {
document.querySelector("#pause_btn").addEventListener("click", () => {
playing = !playing
if(playing) {
document.querySelector("#pause_btn span").innerText = "Pause"
document.querySelector("#pause_btn i").innerText = "pause_circle_outline"
} else {
document.querySelector("#pause_btn span").innerText = "Resume"
document.querySelector("#pause_btn i").innerText = "play_circle_outline"
}
});
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<body>
<a class="waves-effect waves-light btn" id="pause_btn">
<span>Pause</span>
<i class="material-icons right">pause_circle_outline</i>
</a>
</body>
</html>
Related Topics
Iterate Through Colors in JavaScript
Android Webview, Loading JavaScript File in Assets Folder
Replacing Normal File Upload Input with an Image
Why Blocking Event Loop Does Not Block CSS Animation
Javascript: How to Determine How Much User Scrolls After Reaching the End of a Page
Document.Body.Scrollheight Yielding Two Different Results in Firefox/Chrome
Nav-Collapse Not Working [Twitter Bootstrap]
Jquery UI Datepicker: Don't Highlight Today When It Is Also Selected
How to Parse CSS Font Shorthand Format
Highlight Active Menu Item on Scroll
Expand Div Over Others on Mouse Over Jquery
Webview Methods on Same Thread Error
How to Show a Label Beyond a Certain Zoom Level in Leaflet
How to Include CSS Files from an MVC Partial Control
Webkit Scrollbar Dynamic Styling
Retrieving or Changing CSS Rules for Pseudo Elements
How to Use Feature Detection to Know If Browser Supports Border-Radius? (Including IE9)