Author

Topic: javaScript need help (Read 225 times)

legendary
Activity: 3654
Merit: 8909
https://bpip.org
July 07, 2019, 04: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 */ }
});
sr. member
Activity: 490
Merit: 275
July 07, 2019, 03:58:34 PM
#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) +' [more 🡲]';

            e.onclick = function(){
                e.innerHTML = oldtext;
            }
        }
    })
legendary
Activity: 3654
Merit: 8909
https://bpip.org
July 07, 2019, 08:34:51 AM
#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 */ });
sr. member
Activity: 490
Merit: 275
July 07, 2019, 05:09:47 AM
#2
mention @suchmoon are there any ideas? to access quote content without internal quotations?
sr. member
Activity: 490
Merit: 275
July 02, 2019, 09:51:29 PM
#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
Jump to: