I have a search input tag, and I wanted to set a placeholder. In place holder I need to keep a magnify icon, how to do it in jquery? below is the code I tried
$('.gridjs-head .gridjs-search .gridjs-search-input').attr("placeholder", "<i class='mdi mdi-magnify'></i> Search...")
I needed to use this path because I’m using grid.js to render table in my django project
2
Answers
Please try below code:
Since you cannot include html code inside a placeholder attribute you can’t use the css class strategy to style its text.
Using the unicode character sequence it’s the key.
I showed in this demo two ways to embed it inside the placeholder attribute:
󰍉
unicode to string before composing the string
When bypassing the css class strategy, you are expected to set the
font-family
asMaterial Design Icons
that I did defining a rule forinput::placeholder
.This demo uses the input element
test
that the javascript retrieves using the id selector. You should just replace it with your selector.gridjs-head .gridjs-search .gridjs-search-input
but since I used vanilla js instead of jQuery, it would require you to loop for each element returned in the collection before invoking.setAttribute()