0

I have an input type file connected to a label ( connected by for="uploadFileVideo"), when I click my label the function in script is supposed to be fired. The problem is that nothing happen when the selection is by class ( ".lbl") only when i use element ID, I want to convert the function in my script to javascript function ( function justClickedAlbl(){//Do Somthing} ), maybe it will solve my problem. Is it possible to convert ?

//HTML
     <label id="addVideo" for="uploadFileVideo" class="lbl colors" >Add Video</label>
     <input id="uploadFileVideo" type='file' style="width: 300px; display: none" />
//Script
$(".lbl").click(function (evt) {
//Do something
});
3
  • Can you make a fiddle and show what is not working? Commented Sep 30, 2014 at 11:28
  • maybe it will solve my problem -- I doubt it, if jQuery isn't working for you, it's because your not using it properly. Perhaps it's the missing parenthesis at the end of your snippet? Commented Sep 30, 2014 at 11:28
  • This is not the problem Commented Sep 30, 2014 at 11:30

2 Answers 2

1

You can target the label

$(document).ready(function(){
    $("label[for='uploadFileVideo']").on('click', function(){
         // Your code
    });
});
Sign up to request clarification or add additional context in comments.

Comments

1

This will work:

$(function(){
   $(".lbl").click(function (evt) {
       // Do something, 
       // here you can do anything you want to 
       // be executed when label is clicked
   });
});

You have to attach event when DOM is loaded.

4 Comments

Done, thanks :) it was mechanical error while copying the code from OP, So I think it doe not deserve down vote ;)
Thanks, but how to use it ? I thought about this format : function dodo() and to add my label onclick=dodo()
if you have separate function called dodo() you can call it within //Do something
@George indeed there is was not error in that part, just I've made it ;)

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.