All we need is an easy explanation of the problem, so here it is.
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="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">This is the text</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 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="#" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener">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.
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0