2

in my code three input type=file elements for those css style is bind with button id of input tag. its working fine

//<![CDATA[ 
$(window).load(function() {
    $('.new_Btn1').bind("click", function() {
        $('#html_btn1').click();

    });
    $('.new_Btn2').bind("click", function() {

        $('#html_btn2').click();
    });
    $('.new_Btn3').bind("click", function() {

        $('#html_btn3').click();
    });
});//]]>

i want to minimize my code as single one instead of three, how i can achieve ?

0

1 Answer 1

4

Give all your buttons the same class, e.g. class="new_Btn", and a data attribute linking them to their html_btn, e.g.

<button class="new_Btn" data-file="html_btn1">...</button>
<button class="new_Btn" data-file="html_btn2">...</button>
...

Then use the JS:

$(function() {
    $(".new_Btn").click(function() {
        $("#" + $(this).data('file')).click();
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.