I am a jQuery noobie, and have been trying to add a script to change the id of a div onClick.
Here is a jsfiddle example.
$(function accept() {
$("div:scrollwrap").attr('scrollwrap','highlight');
});
Thanks :)
I am a jQuery noobie, and have been trying to add a script to change the id of a div onClick.
Here is a jsfiddle example.
$(function accept() {
$("div:scrollwrap").attr('scrollwrap','highlight');
});
Thanks :)
if you want to change the div with the id scrollwrap to have the id highlight:
$(document).ready(function() {
$("#checkbox2").click(function() {
$("#scrollwrap").attr('id','highlight');
});
});
remember an ID is unique, so this should only affect one element. if you want to affect multiple use classes and the functions .addClass()/.removeClass()
this is how you change a ID:
$(function accept(){ //makes sure your document is ready
$('div#scrollwrap').attr('id', 'highlight')
})
(i assume scrollwram is you ID)
The first parameter of attr
should be the attribute name, not the current value:
$(function accept() {
$("div#scrollwrap").attr('id','highlight');
});
However, reading your jsFiddle code, you appear to have a class of highlight and not an ID. Here is my edited version with what I think you are trying to achieve.
Note that I have changed the following:
.click()
addition)More resources (jQuery docs):