Hide DOM object in jquery but determined by other object
how best to use jQuery to cause this link with class: "morelink_L3" to be hidden if the div that contains this text: "We understand things..." is less than 550 characters ?
The fact that this div has no class or id makes it tricky for me - there is option of using "find() but that didnt work when i used it.
this is what i tried:
if($(".story_L3 > div").text().trim().length < 550)
{
$('.morelink_L3').hide();
}
this is the html with problem:
Section Description
We understand things change in life and at work and we want to make sure you’re ready for anything. We have a host of information available to help you understand what you need to do and how we can support you through any change.
</div>
<span class="morelink_L3">Read More</span>
</div>
</div>
2 Answers
2
You can use :eq() to target an element by its index in its parent. In this case the second div would be :eq(1). Try this:
:eq()
div
:eq(1)
if ($(".story_L3 > div:eq(1)").text().trim().length < 550) {
$('.morelink_L3').hide();
}
https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
Section Description
We understand things change in life and at work and we want to make sure you’re ready for anything. We have a host of information available to help you understand what you need to do and how we can support you through any change.
</div>
<span class="morelink_L3" value="True">Read More</span>
</div>
</div>
Also note that you could use a single call to toggle() providing the boolean condition to hide/show the relevant element:
toggle()
$('.morelink_L3').toggle($(".story_L3 > div:eq(1)").text().trim().length > 550);
You should use filter()
filter()
$(".story_L3").filter(function() {
return $(this).children('div').text().trim().length < 550
}).next('.morelink_L3').hide();
https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
Section Description
We understand things change in life and at work and we want to make sure you’re ready for anything. We have a host of information available to help you understand what you need to do and how we can support you through any change.
</div>
<span class="morelink_L3" value="True">Read More</span>
</div>
</div>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Popular posts from this blog
Opening a url is failing in Swift breakpointing inside the callback and logging success shows false. I added itms-apps to my plist: LSApplicationQueriesSchemes and put this in my app delegate: func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { return true } func moreTapped() { let url = NSURL(string: "itms-apps://itunes.com/developer/quantum-productions/id979315877") if #available(iOS 10.0, *) { UIApplication.shared.open(url! as URL, options: [:], completionHandler: {(success: Bool) in }) } else { UIApplication.shared.openURL(url! as URL) } } Are you testing on a real device? – rmaddy Jun 21 at 23:57 I try on a device, get "Cannot Connect to App Store". Device is online ...
const player = new window.Plyr('#player', {keyboard: {global: true,},tooltips: {controls: true,},captions: {active: true,},iconUrl: '/js/plyr.svg',autoplay: true});player.source = {type: 'video',sources: [{src: '//youtube.com/watch?v=qh7qaYX11AU',provider: 'youtube',}],}; Why People Love Porsche | WheelHouse Download var switchTo5x=true;stLight.options({publisher: "8370abff-a8c4-40e1-9890-b965a65c3b93", doNotHash: false, doNotCopy: false, hashAddressBar: false}); Why People Love Porsche | WheelHouse Video Channel: Donut Media Air Cooled Porsches have exploded in popularity recently, with everyone clamoring to get their hands on one. But why? What makes people go crazy over these old German sports cars. Nolan heads down to Benton Performance in Anaheim, CA to find out. Thank you John! WheelHouse answers all the questions about the automotive world you never thought to ask. Nolan Sykes looks at the history, sociology and psychology behi...
Why this code fails to compile with gcc 4.8.5 while it compiles fine with clang #include<iostream> using namespace std; int main() { const int k = 10; // Capture k by value auto myl = ...
Comments
Post a Comment