If the href attribute is empty, I would like to eliminate the parent element

Could someone help me with removing the parent div if the href attribute is empty? Here's the code I tried, but it doesn't seem to be working as expected. Any suggestions?

$("#cs-gallery .et_pb_module_inner .dnext_thumbs_gallery_top_holder .dnext-thumbs-gallery-top .dnext-thumbs-gallery-active  .dnxte_thumbs_gallery_child .dnext-thumbs-gallery-item a").filter(function () {
    return this.attr('href').length == 0;
}).remove();

Answer №1

Developed customized HTML and JavaScript code. Experiment with your own selectors.

$("#elements a").filter(function () {
    if($(this).attr('href').length == 0)
    {
        console.log('test');
        $(this).parent().remove();  
    }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="elements">
    <div><a href="">AAA</a></div>
    <div><a href="bbb.html">BBB</a></div>
    <div><a href="#">CCC</a></div>
    <div><a href="">DDD</a></div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Convert the array to a JSON format

My goal is to design a form based on a JSON file to store settings. This will make it appear database-driven, while actually being file-driven, which can help set up the database and other configurations easily. I am almost there but struggling with submit ...

Smoothly animate the height change of dynamically inserted content within a DIV using CSS transitions

Here is the template I am currently working with: <div class='content'> {{content}} </div> Along with the following style: .content { margin-top: 30px; background-color: skyblue; width: 300px; transition: all linear 0.5 ...

Carousel With Multiple Items Displayed Simultaneously In Bootstrap

Is there a way to create a carousel with multiple items in Bootstrap 4? The documentation talks about multiple carousels, but not specifically about how to display multiple items within a carousel. ...

The functionality of tinymce setContent can only be activated by directly clicking on it

Everything is running smoothly with the code below: $('.atitle').on('click', function(){ console.log('323'); tinymce.get("ed").setContent("<p>lorem ipsum</p>"); // it's working ...

Embedding HTML in a Xamarin Forms Label

I am currently developing a mobile app for my website using Xamarin Forms. One of the challenges I am facing is styling HTML content stored in a database field. Although I am utilizing https://github.com/matteobortolazzo/HtmlLabelPlugin, I am struggling t ...

Enhancing a class's properties from its parent component using React

Recently, I decided to dive into React by taking on the challenge of rebuilding the Google Weather app. My main objective is to have the main section update whenever a day is selected. Initially, I believed that updating the props within handleSelectionAt( ...

Displaying a success dialog after closing a Bootstrap modal

I have set up a bootstrap modal containing a form. Upon submitting the form, the form content is hidden and a bootstrap alert message is displayed. However, upon clicking the bootstrap popup, the same alert message is shown in the popup instead of displayi ...

Tips for clearing floated images when the sidebar is also floated

Can someone assist me with this code snippet? I am trying to figure out a way to clear the nearest floated block. It seems that whenever I use the clear property, it clears any floated blocks on the page, even if they are in a different div. Here is the ...

Finding the initial visible iFrame in a browser window and displaying its content

It's quite a strange situation... This issue only pertains to IE8 and older versions. So, there's this iFrame that's popping up (and I have no way to control or assign an ID to it), thank you Telerik! // The only way to target it would be: ...

Moving the webpage into the realm of mobile and tablet devices

Over the next few weeks, I will be working on transitioning my website content to have both a mobile and tablet version. During this process, I have some questions: What is the best way to redirect users to the correct site based on their device/browse ...

Creating a gradient border that rotates 360 degrees on mouse hover

.brand-img::after { content: ''; position: relative; background-image: url('https://i.sstatic.net/Y2vyB.png'); background-repeat: no-repeat; float: left; margin-left: 15px; transition: all 1.8s ease; width: 135px; height: 135px ...

Deactivating Node.js files in vsCode for client-side JavaScript files

I'm facing a major challenge when it comes to coding with JavaScript. I have a JavaScript file that is using Node.js, which means I am unable to manipulate the DOM elements. Take this code snippet for example: var form = document.getElementsByClassNa ...

How can I make a CSS transition activate only on width increases, not decreases?

My element's width changes under different conditions, and I've implemented CSS with a transition for the width: .element-class { transition: width 500ms ease 0ms; } However, I only want the transition to occur when the width is decreasing. ...

The database isn't returning any results when performing an Ajax search in Laravel

I am facing an issue with my form. I want to incorporate a dynamic typeahead feature in one of the input fields. The error message I am encountering is Failed to load resource: net::ERR_BLOCKED_BY_CLIENT advertise-ajax?term=b&_type=query&q=b ...

"Implement a jQuery fade-in effect following a collective toggle action

After looping through the hidden elements, the $("span#slogan").fadeIn("slow"); does not execute. How can I ensure that the fadeIn is the last action to be performed? <style type="text/css> #hidden span{ display:none; float:left; font-siz ...

Difference in values of $(document).height() as compared to $(document).scrollTop() added to $(window).height()

I am currently working on a project where I need to detect when an element enters the view in order to make it fade in. My initial approach was to track the element's vertical position on the page and trigger the fade-in effect when the scroll value w ...

Map Loader for GeoJson Leaflet Integration

Although my English skills are not perfect, I will do my best to explain my issue. I have some knowledge of javascript / html / ajax and I have created a webgis using Leaflet. The problem arises when loading a large geojson file onto the map - it takes qui ...

Preventing page reload by using event.preventDefault() does not work with Ajax Form

I've been working on a code snippet to submit a form using Ajax without any page reloads: $( document ).on('submit', '.login_form', function( event ){ event.preventDefault(); var $this = $(this); $.ajax({ data: ...

Webpack fails to handle CSS background images

I'm having trouble with my Webpack configuration as it's not processing CSS images set in the background property: background: url('./hero.jpg') no-repeat right; This is resulting in an error message that reads: ERROR in ./src/app/comp ...

How jQuery can be leveraged to eliminate HTML elements within a dropdown menu

<script> $(document).ready(function() { $('.notification .tools .remove').on('click', function () { alert('hola'); $(this).parentsUntil('.notification').remove(); }) ...