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

115
Vistas
There's no focus effect when using ajax to embed html into current page and set focus

I'm developing asp.net core and test in Edge browser(version: 96.0.1054.62).

I'm send ajax request and get the html content, then I embedded the html block into current page. After that, I set focus on the html elment in the html block. But I cannot see the focus effect when I call the setFcous function.

In general, when I set focus on one elment, it will have black border wrap it like fhe following.

enter image description here

The following is the code sample:

Index.cshtml

<form>
    <input id="btnDelete" value="Delete" type="button" style="width: 60px" />
</form>

<div id="divInputs" style="display: none">
</div>

<script type="text/javascript">
function setFocus(elementId) {
    var obj = document.getElementById(elementId);
    if (isDefine(obj)) {
        console.log(obj);
        obj.focus();
    }
}

function isDefine(obj) {
    return !(obj == undefined || obj == null)
}

$(function () {
    $('#btnDelete').on('click', function () {
        $.get('/Home/Delete?', (data) => {
            $('#divInputs').html($(data));
            $('#divInputs').show();
            setFocus('btnAction');
        });
    });
});
</script>

HomeController.cs

public IActionResult Delete()
{
    return View("Delete");
}

Delete.cshtml

@{
Layout = null;
}

<div>
    <input id="btnAction" class="button" type="button" value="Delete"/>
    <input id="btnCancel" class="button" value="Cancel" type="button"/>
</div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The focus is set to the button from your code. You can test it with adding the following style to your page.

<style>
    input:focus {
        background-color: yellow;
    }
</style>
about 4 years ago · Juan Pablo Isaza Denunciar
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