1
I believe it should be simple, but, I did not get a perfect functioning.
I am developing a hotsite to provide some slides, theories and codes during the realization of Codelab’s in certain programming languages, created a menu to separate by topics and subtopics.
I’m having difficulty developing a field to perform the search, in the text field I’m using the Javascript function:
$("#search_box").on("keyup", function() {
if(!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g,'');
};
}
var box = $(this);
var keyword = box.val().toLowerCase().trim();
$(".subtopic").each(function() {
var subtopicItem = $(this);
if (subtopicItem.text().toLowerCase().trim().indexOf(keyword) == -1) {
subtopicItem.hide();
}
else {
subtopicItem.show();
}
});
$(".topic").each(function() {
var topicItem = $(this);
if (topicItem.text().toLowerCase().trim().indexOf(keyword) == -1) {
topicItem.hide();
}
else {
topicItem.show();
}
});
});
When we perform the Subtopic search, the search returns only the Subtopic hiding the others, and also showing the topic in which it is related.
Example 1: searching for the word "Introduction"
HTML & CSS -> Topical
Introducing -> Sub-topic
Java -> Topical
Introducing -> Sub-topic
C -> Topical
Introducing -> Sub-topic
Example 2: when fetching the word "HTML"
HTML & CSS -> Topical
Expected: when fetching the word "HTML"
HTML & CSS -> Topical
Introducing -> Sub-topic
Table -> Sub-topic
Lists -> Sub-topic
Links -> Sub-topic
... -> Sub-topic
... -> Sub-topic
Would like to perform the following function: when researching the topics, also show all the related subtopics in that particular subject.