eric01
eric01

Reputation: 919

How can I combine that javascript and jQuery function to hide a button?

I downloaded the File upload script called Simple Photo Manager. Since I'm more familiar with jQuery functions I want to use them in combination with the already existing JS code from that script.

I basically want to hide the Delete button when it's clicked. Why is the Delete button not being hidden after I click on it? (Note: the JS files are correctly included into the HTML file) Also, the delLink.removeChild and delLink.appendChild are useless here because it was originally intended for a Delete/Restore switch link, but I decided to go for a button instead.

Thanks a lot if you can help me.

The html code is:

<input type='button' id='deleteit' onClick="deleteLinkOnClick
(this, 'delFlag<?=$imgid?>')">

The JS code for creating that element when an image is uploaded is:

var image_del_link = par.createElement('input');
image_del_link.type = "button";
image_del_link.value = "Delete";
imgdiv.appendChild(image_del_link);

The function for the onclick is: (I tried to write the jQuery function at the bottom)

function deleteLinkOnClick(delLink, delFlag) {
    var par = window.document;
    var imgDiv = delLink.parentNode;
    var image_hidden = delFlag == '' ? imgDiv.childNodes[2] : par.getElementById(delFlag);

    if (image_hidden.value == '1') {

        image_hidden.value = '0';
        delLink.removeChild(delLink.childNodes[0]);
        delLink.appendChild(par.createTextNode("Restore"));
        delLink.style.color = '#FF0000';
    }
    else {
        image_hidden.value = '1';
        delLink.removeChild(delLink.childNodes[0]);
        delLink.appendChild(par.createTextNode("Delete"));
        delLink.style.color = '#64B004';
    }

    $(document).ready(function(){
        $(image_del_link).click(function(){
            $(this).hide();
            });
        });
}

Upvotes: 0

Views: 107

Answers (2)

Nemoy
Nemoy

Reputation: 3427

Try :

$("#deleteit").live("click", function(){
    $(this).hide();
});

Upvotes: 0

Taha Paksu
Taha Paksu

Reputation: 15616

Here it is.

$("#deleteit").click(function(){
    $(this).hide();
})

Upvotes: 1

Related Questions