'Adding image before the "contains" using javascript
Need help on this code below. I don't want to replace the text on which I called in my "a:contains". The problem is where do I need to put the ::before on the script below.
Link: https://jsfiddle.net/onw7aqem/
$(document).ready(function() {
$("a:contains(This is the text)").css("content", "url('https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U')");
});
<a href="#">This is the text</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Solution 1:[1]
Consider the following.
$(function() {
$("<div>").css("content", "url('https://i.picsum.photos/id/237/200/300.jpg?hmac=TmmQSbShHz9CdQm0NkEjx1Dyh_Y984R9LpNrpvH2D_U')").appendTo($("a:contains(This is the text)"));
});
<a href="#">This is the text</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
This creates a <div> element and appends it to the <a> element.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Twisty |
