Trying to access the Selected row of a GridView by using JQuery to find the row with the background-color attribute set to the SelectedRowStyle background color. That color is #FF6600. I've tried
var row = $("tr").find().css("background-color", "#FF6600");
But that just sets all the rows to orange.
var row = $("tr[background-color=#FF6600");
That returns empty
var row = $("tr").find().attr("background-color");
Returns undefined
click(function() { var color = $( this ). css( "background-color" ); $( "p" ). html( "That div is " + color + "." ); });
Set the background color red of the following elements using jQuery. .add (elements) : Create a new jQuery object with elements added to the set of matched elements. Here .add () method adds more elements like "span", "textarea" etc. .css (propertyName) : Get the computed style properties for the first element in the set of matched elements.
.find (selector) Returns: jQuery Description: Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element. version added: 1.0.find (selector)
$( "div" ).click(function() { var color = $( this ).css( "background-color" ); $( "p" ).html( "That div is " + color + "." ); }); Contribute your code and comments through Disqus. Next: Add the following class "myclass" to the matched paragraph elements.
A string containing a selector expression to match elements against. An element or a jQuery object to match elements against. Given a jQuery object that represents a set of DOM elements, the .find () method allows us to search through the descendants of these elements in the DOM tree and construct a new jQuery object from the matching elements.
Try the .filter
method.
var rows = $('tr').filter(function(){
var color = $(this).css("background-color");
return color === "#FF6600" || color === "rgb(255, 102, 0)" ;
});
I haven't tested it, the rgb part may need to be adjusted to account for spacing.
Edit:
or better yet, this takes into account uppercase vs lowercase
var rows = $('tr').filter(function(){
var color = $(this).css("background-color").toLowerCase();
return color === "#ff6600" || color === "rgb(255, 102, 0)" ;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With