Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery create new div with ID?

I have form in my ASP.NET masterPage.master and if i click on submit it call some method from masterPage.master.cs file by ajax (i have it in update panel). But i want improve it with jQuery. So i have this:

$('#submit').click(function () {
            $.ajax({
                type: "POST",
                url: '<% Response.Write("~"+Request.Path); %>',
                beforeSend: function () {
                    $(document.createElement('div')).width($('#formBox').width())
                    .height($('#formBox').height())
                    .css({ backgroundImage: 'url(/Static/Img/bc_overlay.png)', position: 'absolute', left: 0, top: 0, margin: "5px", textAlign: "center", color: "#000", display: "none" })
                    .append("<strong>Načítám</strong><br /><img src='Static/Img/ajax-loader.gif' width='33px' height='33px' alt='loading' />")
                    .fadeIn("slow")
                    .prependTo($('#formBox'));
                    $('#formBox').css('position', 'relative');
                },
                success: function () {
                }
            });
        });

So if i click on submit, new div is creating (there is loading text and image, and cool opacity overlay), but how i give to this div some ID? Because i need use it in

success: function () {
                    }

i need clear this box and write here some text (error or success).

like image 659
John Avatar asked Dec 18 '25 19:12

John


1 Answers

Just set the attribute when you're creating it

$(document.createElement('div')).attr('id', 'theID')//rest of code
like image 87
JohnP Avatar answered Dec 21 '25 11:12

JohnP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!