Reputation: 317
I have got a div containing some html elements. They all have a class named
class="fileItem read write"
.
But there could be an Element with
class="fileItem read write selected"
.
Now I want to get this element with the additional 'selected' tag and edit this. Currently I have an in JQuery
$(".fileItem").click(function(){
// Code
});
which detect an click on one of these fileItems.
Here I want to edit style tag of the element with 'selected' tag. So is there something where I can say get all by class and select the on with "selected"?
Upvotes: 3
Views: 127
Reputation: 158
As far as I know you should be able to combine the two classnames:
$(".fileItem.selected").click(function() {
//your actions
});
Upvotes: 0
Reputation: 1775
Use core java script to do this.
function func() {
alert("Hello, world!");
}
document.getElementsByClassName("fileItem read write selected")
[0].addEventListener("click", func, false);
Upvotes: 0
Reputation: 1249
$(".fileItem").click(function(e) {
e.preventDefault();
$('.selected').css({
'color': 'green'
});
});
Upvotes: 1
Reputation: 4474
$(".fileItem").click(function(){
$(this).find('.selected').style('blah','blah')
});
Something like this will allow you to perform other functions as well as the selected item.
Upvotes: 1
Reputation: 30729
You can simply use this line of code to get the element with the selected
class
$(".fileItem.read.write.selected").click(function() {
// code here
});'
Upvotes: 0
Reputation: 3584
Just chain the desired class names like you would do in a CSS selector:
$(".fileItem.selected").click(function() {
// do stuff
});'
Upvotes: 5