logo
down
shadow

How to hide parent element based on child's text value


How to hide parent element based on child's text value

By : Cmg Cmg
Date : November 22 2020, 02:42 PM
should help you out To see if a string contains another (sub)string you can use indexOf. And check if it is not -1.
Using each() you can loop over all li elements. Taking your jsFiddle (provided in comment) into account, I got this result: http://jsfiddle.net/ub8c6smh/5/
code :
jQuery(document).ready(function($) {
    var string1 = 'string1',
        string2 = 'string2';
    var string1exists= $('li').text().indexOf( string1)!==-1;
    console.log(string1exists);

    $('li').each(function () {
         if ($(this).text().indexOf( string2)!==-1 && string1exists==true) {
             // this child contains string 2
            $('li').hide(); //hide all others
            $(this).show();                    
        }
        if ($(this).text().indexOf( string2)!==-1 && string1exists==false) {
             // this child contains string 2
            $(this).hide();                    
        }
        if ($(this).text().indexOf( string1)!==-1 && string1exists==false) {
             // this child contains string 1
            $(this).hide();                    
        }
    });

});


Share : facebook icon twitter icon
Nokogiri how to get the parent text and not the childs text and reference the text back to its parent

Nokogiri how to get the parent text and not the childs text and reference the text back to its parent


By : user1608130
Date : March 29 2020, 07:55 AM
will help you Let's say I have this sample: , There we go
code :
require 'rubygems'
require 'nokogiri'

doc = Nokogiri::HTML(DATA.read)

nodes = doc.root.css('.foo').collect do |n|
  { :name => n.name,
    :xpath => n.path,
    :text => n.xpath('.//text()').collect{|t|
      { :parent => t.parent.name,
        :text => t.text }}}
end

p nodes

__END__
<html>
<body>
<h1 class='foo'></h1>
<p class='foo'>hello people<a href='http://'>hello world</a></p>
</body>
</html>
use the jquery find() method to hide childs when a parent is selected

use the jquery find() method to hide childs when a parent is selected


By : Jack Houston
Date : March 29 2020, 07:55 AM
hop of those help? I have the following code which i have found from here Click menu with children :
code :
$("a").click(function(e) {
    $(this).closest("li").children("ul").slideToggle().end()
           .siblings('li').children('ul').slideUp();
});
jQuery hide parent block if all childs hidden

jQuery hide parent block if all childs hidden


By : Map Data
Date : March 29 2020, 07:55 AM
it helps some times The question is how to hide parent block if all childs are hidden, and display it if they are visible again? Is it possible to "monitor" block status with jQuery? , Try
code :
$(function () {
    var childs = $("[class^=child]");

    childs.click(function () {
        $(this).hide();
        //check if any child is visible, if not hide the mother element
        if(!childs.filter(':visible').length){
            $('#mother').hide()
        }
    });
});
Hide parent element based on value of child element

Hide parent element based on value of child element


By : Obeid Âssï
Date : March 29 2020, 07:55 AM
I wish this help you I want to create a filter function which hides divs based on values of p tags. The behavior should be the following: , I think this should do the trick :
JQuery code :
code :
function eraseThis() {
    var tagList = $(".rating");
    tagList.each(function(){

        var $this = $(this);
        if (parseInt( $this.text() ) < 5) {
            $this.parent().hide();
        }

    });
}
<div class="movie">
 <p class="rating">2</p>
</div>

<div class="movie">
 <p class="rating">9</p>
</div>
hide parent based on childs content

hide parent based on childs content


By : user523917
Date : March 29 2020, 07:55 AM
should help you out I am trying to hide the parent-div based on the child's content: , A one line solution with contains selector:
code :
$("span.value:contains(0)").closest("div.featurevalue").hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="featurevalue">Number 1: <span class="value">1</span></div>
<div class="featurevalue">Number 2: <span class="value">0</span></div>
<div class="featurevalue">Number 3: <span class="value">1</span></div>
$("div.featurevalue:has(span.value:contains(0))").hide();
Related Posts Related Posts :
  • gulp-minify without rename original files
  • create a link to run javascript in another window
  • Javascript, Uncaught TypeError: Cannot read property "cells" of undefined
  • Express.js and Sequelize: does not define models
  • Serialize table data as IEnumerable within asp.net WebApi
  • Handle WebPack CSS imports when testing with Mocha and Babel
  • Converting JSON string to Angular function?
  • Bootstrap-multiselect is very slow with a large pool of options
  • Writing back to HTML after reading form input doesn't work (Javascript)?
  • Kendo UI Grid: Get the data of Current Grouping state?
  • A function to test if all svg objects are visible
  • how to change src without reloading the page
  • side menu with drop down menu
  • How to store timestamp a JSON object?
  • HTML5 Form Submit
  • Caret Sensurround by circle CSS
  • Chrome local storage deleting after NWJS application closes on Windows
  • cordova inappbrowser referencing elements
  • Passing multiple variables to another page
  • $.when with arbitrary number of deferred objects?
  • Printing different part of page depending on clicked element
  • Read in cookie to Shiny application with embedded javascript
  • Asynchronous array problems
  • Disable button if certain number of checkbox are checked
  • Write a loop that finds a value and returns a color
  • How to make the page layout stay the same after minimized?
  • Looping div elements using jquery
  • Node.js 'request' module wrapper with optional params - how to write this more concise?
  • Javascript , Object property is shown as undefined
  • How to trigger and wait for the result of a notification from a call back function of an event listener
  • How to populate a form box with javascript based on other form box inputs
  • Default/Overridable content for Aurelia template (template parts)
  • Ember, how to reuse same "partial" for "index" and for "show"
  • Display content from database on HTML page via Ajax and PHP
  • exporting logic as a function in express.js
  • Verifying Docusign Connect Signature with X509 Certificate
  • React js get the value from div
  • What does the notation () => mean and how to use it?
  • JQuery Hide/Show one, not all
  • Split string on backslash or forward slash
  • PHP Inside JavaScript - Quotes Issue?
  • ReactJS Unexpected Token ) on Safari only
  • Use lodash to group array into tree "children" structure
  • With D3, how can I avoid SVG graph links being rendered over nodes?
  • Consolidate nested, overlapping <strong> and <em> tags
  • How to Access an array of objects properties?
  • Simple Push Menu in CSS3 and jQuery
  • addEventListener not working for onDragStart
  • Partial string matching in javascript
  • Posting a title along with a Photo using the FB.api
  • Why is my jquery code not working or throwing any errors?
  • Javascript/jquery - Wrap text with tag at specific position
  • Javascript Canvas can't draw multiple curves
  • Javascript move entire span with arrow keys
  • How to stop my character from going outside the div?
  • How to call in plugin options in jquery plugins
  • Remove default submit on modal form button
  • Generate angular model properties by view, when view fields are empty
  • AngularJS - project files layout, injection and scope clarification
  • get text fields that are not empty
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co