There is a block <div id = 'ee'></div> It is necessary that when clicked it would be set id = 'rr' How can this be done?
|
3 answers
To do this, use the attr function.
<div id="ee">content here</div> <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script> <script> $(function() { $('#ee').on('click', function(e) { $(this).attr('id', 'rr'); }); }); </script> - Almost simultaneously =) - Batanichek
|
oh, it seems like he did visibility for a long time, ahead of him :) but I’ll post it anyway, so as not to be wasted
$('#ee').click(function() { $('#ee').attr('id', 'rr'); }); div { width: 100px; height: 100px; } #ee { background-color: #f00; } #rr { background-color: #0f0; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="ee"></div> - Thank you very much) nothing is wasted - Nikita Shchypylov
- @ Nikita Schipilov, yeah, but in any case I think that Andrei Katalkin provided the fastest and right answer :) - MasterAlex
|
Try this option
$("#ee").click(function () { $("#ee").attr("id", "rr"); }); |
id? - Grundy