I know there are a few questions and answers on StackOverflow about using regex in jQuery, but they seem a bit complicated.
I don’t understand why this doesn’t work:
$("div").click(function () {
$(this).parent().className.replace(/photo-\w*/, 'photo-2');
});
It seems like a simple operation: replace the parent of the clicked div (which could have a class something like ‘photo-5’), with the ‘photo-2’
Can someone explain why the above code doesn’t work, and provide the simplest / cleanest method possible do this? Thanks
$(this).parent() will give you a jQuery object. Try this