Topic de CestMichelDrac :

[NIVEAU EXPERT] JQUERY comment retourner un élément STRONG ?

Supprimé
  • 1

https://www.poulpeo.com/reductions-dorcel-store.htm

document.querySelector("#r8314049 > div.c-offer__main > h2 > strong")

Me retourne :
<strong>5€ de remise</strong>

Comment faire pour afficher : 5€ de remise

? https://image.noelshack.com/fichiers/2020/35/2/1598347459-charles-help.png

J'ai essayé
document.querySelector("#r8314049 > div.c-offer__main > h2 > strong").text()

Mais j'ai une erreur "Text isn'ent a function" https://image.noelshack.com/fichiers/2020/35/2/1598347459-charles-help.png

AIDEZ MOI LES GEEK PAR DEPIT https://image.noelshack.com/fichiers/2022/36/1/1662411606-ahi-risitas-el-tison-2-1-1.png
document.querySelector("#r8314049 > div.c-offer__main > h2 > strong").innerHTML
ce selecteur à rallonge....
Tu veux pas mettre un id et appeler l'id plutôt ?

Le 12 septembre 2022 à 00:24:55 :
document.querySelector("#r8314049 > div.c-offer__main > h2 > strong").innerHTML

Cimer mais ca m'affiche '5€ de remise' et non 5€ de remise

Pourquoi .text() ça fonctionne pas ? https://image.noelshack.com/fichiers/2022/36/1/1662411606-ahi-risitas-el-tison-2-1-1.png

$("#r8314049 > div.c-offer__main > h2 > strong").text()

Le 12 septembre 2022 à 00:25:56 :
ce selecteur à rallonge....
Tu veux pas mettre un id et appeler l'id plutôt ?

Je connais rien khey j'ai fait clic-droit "copier JSPath" https://image.noelshack.com/fichiers/2022/36/1/1662411606-ahi-risitas-el-tison-2-1-1.png

Ca donnerait quoi si c'était bien fait ? https://image.noelshack.com/fichiers/2022/36/1/1662411606-ahi-risitas-el-tison-2-1-1.png

Le 12 septembre 2022 à 00:27:53 :
$("#r8314049 > div.c-offer__main > h2 > strong").text()

VM302:1 Uncaught TypeError: Cannot read properties of null (reading 'text')
    at <anonymous>:1:49

J'ai rentré ça dans la console de Chrome :(

Le 12 septembre 2022 à 00:28:58 :

Le 12 septembre 2022 à 00:27:53 :
$("#r8314049 > div.c-offer__main > h2 > strong").text()

VM302:1 Uncaught TypeError: Cannot read properties of null (reading 'text')
    at <anonymous>:1:49

J'ai rentré ça dans la console de Chrome :(

up https://image.noelshack.com/fichiers/2020/35/2/1598347459-charles-help.png

C'est pas du jquery, c'est l'API DOM du navigateur https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

Utilise .textContent

[00:28:04] <CestMichelDrac>

Le 12 septembre 2022 à 00:25:56 :
ce selecteur à rallonge....
Tu veux pas mettre un id et appeler l'id plutôt ?

Je connais rien khey j'ai fait clic-droit "copier JSPath" https://image.noelshack.com/fichiers/2022/36/1/1662411606-ahi-risitas-el-tison-2-1-1.png

Ca donnerait quoi si c'était bien fait ? https://image.noelshack.com/fichiers/2022/36/1/1662411606-ahi-risitas-el-tison-2-1-1.png

Tu mets un id="strong" à ton element <strong> et tu fais $("#strong").text();

Le 12 septembre 2022 à 00:31:07 :
C'est pas du jquery, c'est l'API DOM du navigateur https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

Utilise .textContent

Clé je sais même pas ce qu'est DOM :rire:

Et donc quand j'ai"5€ de remise"comment je peux faire pour que ça retourne"5" ou "5€" par exemple ? https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

.textContent c'est le mieux apparemment https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

Plus léger

Et donc quand j'ai "5€ de remise" comment je peux faire pour que ça retourne "5" ou "5€" par exemple ? https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

Le 12 septembre 2022 à 00:35:15 :

Le 12 septembre 2022 à 00:31:07 :
C'est pas du jquery, c'est l'API DOM du navigateur https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

Utilise .textContent

Clé je sais même pas ce qu'est DOM :rire:

Et donc quand j'ai"5€ de remise"comment je peux faire pour que ça retourne"5" ou "5€" par exemple ? https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

textContent.substring(0, 2);

Le 12 septembre 2022 à 00:42:41 :

Le 12 septembre 2022 à 00:35:15 :

Le 12 septembre 2022 à 00:31:07 :
C'est pas du jquery, c'est l'API DOM du navigateur https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

Utilise .textContent

Clé je sais même pas ce qu'est DOM :rire:

Et donc quand j'ai"5€ de remise"comment je peux faire pour que ça retourne"5" ou "5€" par exemple ? https://image.noelshack.com/fichiers/2017/39/3/1506524542-ruth-perplexev2.png

textContent.substring(0, 2);

Super merci :hap:

document.querySelector("#r8314049 > div.c-offer__main > h2 > strong").textContent.substring(0,1);

Pourquoi quand je tape jquery select a portion of textcontent
sur Google ça me trouve me propose pas "substring" mais que des trucs à rallonge incompréhensibles :(

Ce que google me propose pour sélectionner une partie du texte :peur:

def split_unit(stri):
    to_split = re.findall("\\d+",stri)[0]
    splitted = to_split + stri.split(to_split,1)[1]
    print(splitted)

:ouch:

  • 1

Données du topic

Auteur
CestMichelDrac
Date de création
12 septembre 2022 à 00:22:40
Date de suppression
12 septembre 2022 à 21:46:00
Supprimé par
Auteur
Nb. messages archivés
19
Nb. messages JVC
19
En ligne sur JvArchive 408