Bitcoin Forum
November 18, 2024, 10:45:39 PM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: javaScript need help  (Read 224 times)
omer-jamal (OP)
Sr. Member
****
Offline Offline

Activity: 490
Merit: 275


View Profile
July 03, 2019, 02:51:29 AM
 #1

hi there,  Smiley

I'm try to get quote content without internal quotations

here is include all internal quotations inside the tag this is what I don't want
Code:
var quote = document.querySelectorAll(".quoteheader+.quote");

how can do like that ? only quote content without internal quotations
omer-jamal (OP)
Sr. Member
****
Offline Offline

Activity: 490
Merit: 275


View Profile
July 07, 2019, 10:09:47 AM
 #2

mention @suchmoon are there any ideas? to access quote content without internal quotations?
suchmoon
Legendary
*
Offline Offline

Activity: 3864
Merit: 9090


https://bpip.org


View Profile WWW
July 07, 2019, 01:34:51 PM
 #3

mention @suchmoon are there any ideas? to access quote content without internal quotations?

If you want a list of only first-level quotes do this:

Code:
let list_of_first_level_quotes = document.querySelectorAll(".post > .quote");

If you want to remove/ignore the content of inner quotes - you can't do that with a single querySelector, but depending on how you want to process it you can do something like this:

Code:
document.querySelectorAll(".post > .quote").forEach(e => { let without_inner_quotes = e.querySelectorAll(":not(.quote):not(.quoteheader)"); /* do something here */ });
omer-jamal (OP)
Sr. Member
****
Offline Offline

Activity: 490
Merit: 275


View Profile
July 07, 2019, 08:58:34 PM
Last edit: July 10, 2019, 01:37:05 PM by omer-jamal
 #4

Code:
document.querySelectorAll(".post > .quote").forEach(e => { let without_inner_quotes = e.querySelectorAll(":not(.quote):not(.quoteheader)"); /* do something here */ });
thanks so much, this return node list without text node

console.log( without_inner_quotes );


what i want do check every {quote without_inner_quotes} and check innerText.lenght and when lenght  for example > 100 hide quote text something like so if any way to get {quote without_inner_quotes} Children nodes include text node

Code:
    quote2.forEach( function(e){
        if(e.innerText.length > 250)
        {
            let oldtext = e.innerHTML;
            e.innerHTML =  oldtext.slice(0,200) +' <span style="background: #ffeb3b; cursor: pointer;">[more 🡲]</span>';

            e.onclick = function(){
                e.innerHTML = oldtext;
            }
        }
    })
suchmoon
Legendary
*
Offline Offline

Activity: 3864
Merit: 9090


https://bpip.org


View Profile WWW
July 07, 2019, 09:37:48 PM
 #5

what i want do check every {quote without_inner_quotes} and check innerText.lenght and when lenght  for example > 100 hide quote text

Ok, then I guess you could just subtract the length of inner quotes from the total text length, like this

Code:
document.querySelectorAll(".post > .quote").forEach(e => {
    let outer_length = e.textContent.length, inner_length = 0;
    e.querySelectorAll(":scope > .quote, :scope > .quoteheader").forEach(inner => inner_length += inner.textContent.length );
    if (outer_length - inner_length > 100) { /* do something here */ }
});
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!