I have a video content banner that has a text overlay that has 2 states:
State 1: (Font awesome play icon) Watch In Full
State 2: (Font awesome cross icon) Collapse View
Here is a jS fiddle to show this working (without the font awesome icons):
https://jsfiddle.net/vanstone/4xmabz1f/3/
Here is a jS fiddle to show this not working (with the font awesome icons):
https://jsfiddle.net/vanstone/4xmabz1f/4/
The problem I have is that the text toggles correctly in this example, but when I load in the icons on my site it always runs the else statement from the below jS:
<script>
jQuery("#videoWrapper").click(function() {
var videoText = jQuery(".watch-full-tag p").html();
if (videoText === '<i class="fas fa-times-circle"></i> Collapse View') {
jQuery(".watch-full-tag p").html('<i class="fas fa-play-circle"></i> Watch In Full');
// it runs the below on every click event
} else {
jQuery(".watch-full-tag p").html('<i class="fas fa-times-circle"></i> Collapse View');
}
});
</script>
This is resulting in the initial State 1 being changed to State 2 on the first click, but then remaining as State 2 on every click thereafter.
My question is how do I get my if/else statement to run correctly using icons, is this related to use of < i > inside .html();?
html()
at all and not check the actual element in the DOM? – charlietfl