So I have a Jquery if statement that displays different content inside a div using $(".library-content").html("Here is some content!") but I want a section of the content displayed to be dependent on a variable. So if the variable was set to "cats" the content might read "I like cats" and if the variable changes to "dogs" it would read "I like dogs". Is it possible?
here is my code, it is quite long so i tried to shorten it in my example,
var librarycat = 'none' ;
var librarytype = 'none' ;
$( document ).ready(function() {
$("#library-cat").change(function() {
librarycat = $('option:selected',this).val();
if(librarycat != 'none' && librarytype != 'none') {
$(".library-content").html("{% set topic_posts = blog_recent_topic_posts('2941362257', 'audio', 25 ) %}<ul class='test-list'>{% for post in topic_posts|unique('name') %}{% if 'audio' in post.topic_list|map(attribute='name') %}<li><a href='{{post.absolute_url}}'><img src='{{ post.post_list_summary_featured_image }}' class='hs-featured-image'>{{ post.name}}</a><br>{% for topic in post.topic_list %}<a class='topic-link' href='{{ group.absolute_url }}/topic/{{ topic.slug }}'>{{ topic.name }}</a>{% if not loop.last %} {% endif %}{% endfor %}</li>{% endif %}{% endfor %}</ul>");
}
else if(librarycat == 'none' && librarytype != 'none') {
$(".library-content").html("{% set topic_posts = blog_recent_topic_posts('2941362257', 'audio', 25 ) %}<ul class='test-list'>{% for post in topic_posts|unique('name') %}<li><a href='{{post.absolute_url}}'><img src='{{ post.post_list_summary_featured_image }}' class='hs-featured-image'>{{ post.name}}</a><br>{% for topic in post.topic_list %}<a class='topic-link' href='{{ group.absolute_url }}/topic/{{ topic.slug }}'>{{ topic.name }}</a>{% if not loop.last %} {% endif %}{% endfor %}</li>{% endfor %}</ul>")
}
else if(librarycat != 'none' && librarytype == 'none') {
$(".library-content").html("{% set topic_posts = blog_recent_topic_posts('2941362257', 'audio', 25 ) %}<ul class='test-list'>{% for post in topic_posts|unique('name') %}<li><a href='{{post.absolute_url}}'><img src='{{ post.post_list_summary_featured_image }}' class='hs-featured-image'>{{ post.name}}</a><br>{% for topic in post.topic_list %}<a class='topic-link' href='{{ group.absolute_url }}/topic/{{ topic.slug }}'>{{ topic.name }}</a>{% if not loop.last %} {% endif %}{% endfor %}</li>{% endfor %}</ul>")
}
else {
$(".library-content").html("{% set topic_posts = blog_recent_topic_posts('2941362257', 'audio', 25 ) %}<ul class='test-list'>{% for post in topic_posts|unique('name') %}{% if 'Insurance' in post.topic_list|map(attribute='name') %}<li><a href='{{post.absolute_url}}'><img src='{{ post.post_list_summary_featured_image }}' class='hs-featured-image'>{{ post.name}}</a><br>{% for topic in post.topic_list %}<a class='topic-link' href='{{ group.absolute_url }}/topic/{{ topic.slug }}'>{{ topic.name }}</a>{% if not loop.last %} {% endif %}{% endfor %}</li>{% endif %}{% endfor %}</ul>")
}
});
where you see the word 'audio' I would like this to be depended on a select element.
ifstatement, and that it would be enough to solve your issue.