Resusing jQuery functions
I'm working on a web project which is done using php and jQuery. All the jQuery functions are being 开发者_高级运维stored in one .js file. All the modules of the project has similar functionality.
My problem is when a certain function is used for 2 or 3 times it stops working for other instances. For example, to retrieve the clicked element's name first I was using$('#articleCPanel #editorPanelActions input').click(function () {
var actionName= ($(this).attr('name');
});
but then after couple of modules this was no longer working. I had to use the below code instead
$('#videoCPanel #editVideo fieldset input').click(function(event) {
var actionName = $(event.target).attr('name');
});
I would like to know is there any explanation for this?
I appreciate any help
Thanks in advance :)I think it just comes down to conventions of the tags you are looking at. alt is commonly used on links (a tags), while name is not. So your first piece of code uses the alt tag of the link.
The second piece of code is only looking at input tags (presuming this is a textbox?). alt tags are not commonly associated with an input tag, but a name attribute would be used.
Without seeing the html (or php), your question is hard to answer.
精彩评论