I have a rails app, where I have 2 models, user and notice. A user has a single notice. I’m using jQuery to implement the ‘edit’ and ‘update’ methods for notice.
In order to send the correct ‘id’ of the notice to my notice controller i’ve created a div tag in the view with the id of the notice, so that i can get the id of the notice using jQuery.
I was wondering whether this is the right way to go about implementing CRUD operations using jQuery(the having a div with the id of the notification part) ??
Any thoughts would be appreciated!
Thanks,
Punit
The Yes version:
In HTML DOM stuff (and jQuery selectors too, I think 🙂 ) it is important not to have the same id attribute for more than one div, so for the future I would recommend adding a string or a character before the id, eg.:
and getting it:
var id=$(whatever).attr(‘id’).substring(3);
substring with one parameter skips first n characters.
It is helpful when You have more than one source of ids on the page (things from different tables, etc.)
The No version:
Some people use jQuery.data() for storing the id. I cannot compare the problems. For me the id is the default