Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
How to use one single jquery function for many controls like img tag ,upload tag
Posted
Comments
Nathan Minier 15-Sep-14 8:14am    
Be more specific in terms of what the function is, what you want to do, etc.
[no name] 19-Sep-14 2:44am    
Please share your code. Are you looking for the class selector?

you aren't very specific about what you are trying to achieve so here is something that fits for when the element is clicked.

assign some arbitrary class name to all of the elements that you want handled.

JavaScript
$(".someClass").click(function(event) {
    // this function will get called whenever an element with that
    // class name is associated with it.
});


I don't understand why you would want one function handle everything??
 
Share this answer
 
Unclear on what you actually want to achieve.

Are you looking for something as follows
C#
$(".someDivClass input[type=text]").blur(function(){
//action when a textbox thats inside a div(class="someDivClass") is blurred 
});


$(".someDivClass a").click(function(){
//action when a link thats inside a div(class="someDivClass") is clicked 
});

//applying src to an image
$(".someDivClass img").attr("src","url")


This can be achieved for all the images,links etc in the body by merely removing ".someDivClass" from the above snippets
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900