Bitcoin Forum

Other => Off-topic => Topic started by: omer-jamal on July 03, 2019, 02:51:29 AM



Title: javaScript need help
Post by: omer-jamal on July 03, 2019, 02:51:29 AM
hi there,  :)

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
https://i.ibb.co/2yDTQL7/image.png


Title: Re: javaScript need help
Post by: omer-jamal on July 07, 2019, 10:09:47 AM
mention @suchmoon are there any ideas? to access quote content without internal quotations?


Title: Re: javaScript need help
Post by: suchmoon on July 07, 2019, 01:34:51 PM
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 */ });


Title: Re: javaScript need help
Post by: omer-jamal on July 07, 2019, 08:58:34 PM
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 );
https://i.ibb.co/9w5XnSM/kjk.png

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;
            }
        }
    })


Title: Re: javaScript need help
Post by: suchmoon on July 07, 2019, 09:37:48 PM
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 */ }
});