I have a very complicated chat application running, and more than one chat pan, chat entries, chat submissions, etc. In the same window I was going to do something like this ....
& lt; Input type = "text" category = "chat text" id = "chattext-42" & gt; & Lt; Input type = "text" class = "chattext" id = "chetttex-93" & gt; & Lt; Input type = "button" class = "chatbummit" id = "chat-emit-42" & gt; & Lt; Input type = "button" class = "chatsubmit" id = "chatsubmit-93" & gt;
... etc (Of course this is very simple, they will be in different divisions, different visibility etc.), so when they are one. Click on Chatsbummit, then it will get that ID and find the last two letters for Chat ID. It presents some problems, because the ID needs to be changed, if the ID changes, and only plain undefected for me.
Then I missed the data () feature in jQuery ... I thought, maybe I would like it more:
& lt; Input type = "text" category = "chat text" & gt; ... and this one & lt; Input type = "button" class = "chatbumit" & gt; Add a .data ("id", 42) to ... and a .data ("id", 42)
add
so that when they click on the chatbudget, this is the ID, and then the chat text with that ID Searches and processes it. But by looking at the documentation, I do not find it easy to find. For example, suppose that in this case the target of the event 42 is the chat with the data ('id') ...
var id = $ (event.target) .data ( ' Id '); // set it to 42 var chattext = ... and
and here I go into trouble how do I know which DOM element contains a range of chat text and 42 Matches a data ('id')? Is there any easy way or do I have to find .chattext for each of the 42's IDs? Or is there a more easy way to do this?
I had considered the possibility of the container div with the ID, which would have to do it, I think? A little easier to get but if it works, then it can deal with things in other container devices so that it does not make long term solutions.
EDIT: Verbatim seconds after posting it, I have come to know this: Extending the selector to data in which information is included, I will try it, and in the meantime, is it this way Is totally stupid to deal with?
I do not see anything wrong with using "ID", and certainly the fastest to find things The method will be if you use caution about the method you use (say, always by adding numeric keys after the "-" or "_" character) then you can split the key value using only one regex Can be: Or whatever. Of course, you can use the "data" feature to store the key, if it is unattractive to get it from "id" value. This will not bother me, though. Edit & mdash; If you want to "clean it up", you can always type a few jQuery plugins so that you can get the key, and return the selector to find a given "partner" element. / P>
var key = $ (this) .attr ('className'). Replace (/ - (\ d +) $ /, "$ 1");
Comments
Post a Comment