Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
Getting the child element id from parent and rendering the button in the id in parent component react js

I have one parent component and child component. I have to get the id from child in parent component and place button in the parent component using ReactDom.render(somebutton, Id_of_the_child).

This one I have written in the component did update. But it's not working. Can anyone help me with this why this isn't working? Not able to get the child id in parent itself.

Index.js:

import React, { Component } from "react";

class parentComponent extends Component {
    constructor(props) {
         super(props); 
    }

    onClick = () =>{
         console.log("some functionality is done")
    }

    componentDidMount(){
        if(document.getElementById("child_place_holder")){
             ReactDOM.render(< button onClick={this.onClick} 
        />,$("#child_place_holder")[0]);

        }
    }

    render() {
        return (
          <div>
             <ChildComponent/>
          </div>
        );
    }
}

export default parentComponent;

ChildComponent.js:

import React, { Component } from "react";

class ChildComponent extends Component {
   constructor(props) {
       super(props);  
   }

   componentDidMount(){}
  
   render() {
      return (
        <div>
          <span id = "child_place_holder"> </span>
        </div>    
      );
   }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda