I am trying to make a remove active function but it wont register and I got an error on my console:
Uncaught TypeError: Cannot read properties of undefined (reading 'remove')
Is there any other way i can add a remove function apart from document.queryselector
or document.queryselectorAll
as i have tried them as well and still doesn't work. I have added the all the code below.
JavaScript
var container = document.getElementById("btn-tab");
var current = container.getElementsByClassName("active");
var press = document.getElementById(this.btn);
current.className.remove("active");
press.className += " active";
HTML
<div id="btn-tab" class="tabs">
<button id="tabnews" class="tablinks active" onclick="openFeed(this)">LATEST NEWS</button>
<button id="tabevents" class="tablinks" onclick="openFeed(this)">EVENTS</button>
<button id="tabgroup" class="tablinks" onclick="openFeed(this)">GROUP</button>
</div>
<div id="tabs-feed">
test123
</div>
Theme Functions
function js_swappost() {
//swap_post_type is a local name for the ajax call and is onlyused in her
wp_enqueue_script ("swap_post_type", get_stylesheet_directory_uri() . "/assets/js/ajax.js", array('jquery')) ;
//ajax_var is declaring a variable that is available in the client script for accessing data about the Ajax handler
//nonce is a security featur to prevent injection of Ajax calls
wp_localize_script('swap_post_type', 'ajax_var', array('ajaxurl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('swapposttype'))) ;
}
add_action("wp_enqueue_scripts", "js_swappost") ;
//This is the function to be called when the Ajax call is made
function swap_post_ajax() {
//Get the post data type to be shown, defaults to Latest News
$type = (isset($_POST["postType"])) ? $_POST["postType"] : 'latestNews' ;
//Get the nonce security code, default to 0
$nonce =(isset($_POST["nonce"])) ? $_POST["nonce"] : 0 ;
//Check that the security code is correct
if (wp_verify_nonce($nonce, 'swapposttype')) {
if ($_POST == "latestNews"){
// latestnewsFeed() ;
echo '<p>test</p>';
}
else{
if ($_POST == "events")
// eventsFeed();
echo '<p>test1</p>';
else {
// groupFeed();
echo '<p>Why is this not working?</p>';
}
}
}
else {
echo 'Security Alert' ;
}
wp_die() ; //Needed to stop WordPress processing normally
}
//This is the code that actually registers the Ajax call wp_ajax is need with the element of 'swap_post_ajax' used to map to the function declared above
add_action('wp_ajax_nopriv_swap_post_ajax', 'swap_post_ajax') ; //Register the event for logged out users
add_action('wp_ajax_swap_post_ajax', 'swap_post_ajax') ; //Register the event for logged in users
CSS
button#tabnews {
position: relative;
bottom: 130px;
font-size: 40px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: center;
justify-content: space-between;
align-items: flex-start;
font-family: highvoltage-rough;
background: #17CBC5;
width: 50%;
padding: 20px;
color: white;
border-radius: 0px;
margin: 5px;
font-style: normal;
font-weight: 400;
}
button#tabevents {
position: relative;
bottom: 130px;
font-size: 40px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: center;
justify-content: space-between;
align-items: flex-start;
font-family: highvoltage-rough;
background: #17CBC5;
width: 50%;
padding: 20px;
color: white;
border-radius: 0px;
margin: 5px;
font-style: normal;
font-weight: 400;
}
button#tabgroup {
position: relative;
bottom: 130px;
font-size: 40px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: center;
justify-content: space-between;
align-items: flex-start;
font-family: highvoltage-rough;
background: #17CBC5;
width: 50%;
padding: 20px;
color: white;
border-radius: 0px;
margin: 5px;
font-style: normal;
font-weight: 400;
}
@media screen and (max-width: 768px) {
.tablinks {
display: flex;
justify-content: space-between;
margin-left: 5px;
margin-right: 5px;
margin-top: 20px;
max-width: 50%;
text-align: left;
height: 70px;
}
}
.active{
color: blue;
}
.tablinks:hover {
background-color: #17cbc5;
color: white;
opacity: 1;
}
.tablinks .active {
background-color: #17cbc5;
}
.tablinks{
text-align: center;
position: relative;
margin-top: 0;
margin-bottom: -135px;
top: -127px;
}
@media (max-width: 959px) {
.tablinks {
text-align: center;
position: relative;
margin-top: 0;
margin-bottom: -160px;
top: -158px;
}
}
@media (max-width: 650px) {
.tablinks {
text-align: center;
position: relative;
margin-top: 0;
margin-bottom: -170px;
top: -257px;
}
}
@media (max-width: 425px) {
.tablinks {
text-align: center;
position: relative;
margin-top: 0;
margin-bottom: -74px;
top: -111px;
}
}
@media (max-width: 375px) {
.tablinks {
text-align: center;
position: relative;
margin-top: 0;
margin-bottom: -88px;
top: -113px;
}
}
@media (max-width: 366px) {
.tablinks {
text-align: center;
position: relative;
margin-top: 0;
margin-bottom: -151px;
top: -166px;
}
}