I need to select dynamic id using JQuery, and once I select it then I need to do some action on it.
<input id="content_photos_attributes_1355755712119_image" name="content[photos_attributes][1355755712119][image]" size="30" type="file">
The HTML contains both ID and Name attribute. I dont care which one I can select as long it is selected.
This is what I have tried so far, without success.
<script type="text/javascript">
jQuery.noConflict();
jQuery("#add_photo_product").click(function() {
alert("Handler foooor .click() called.");
//var field = $("input[id *= 'content_photos_attributes_']");
var field = $('input[name*="content"]');
alert (field);
});
The first selector works, and I can grab it easily. As soon as it is executed, then DOM is populated with the one that I can get hold of (Under HTML code).
I have tried various combinations, but it is always null.
How can I do this?
try replace this
by this
you are not making the
idwhich is shown in your html codeto run you your test better do easy alert just to test if it works
like that
EDIT2>
if you have the id like a variable then you can also do it like that