I am trying to find an element with a particular style and change its style to something else.
Here is the html element
<table style='width: 555px;'>
<tr>
<td>blablabla</td>
</tr>
</table>
Now I am trying to find the table with width 555px and change it to 650px using jquery.
$('table[style*=width:555px]').css("width", "610px");
But this is not working. Can somebody spark an idea please?
NOTE: For some reason I cannot change the html.
Projects In JavaScript & JQueryjQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element.
How to select an element by name with jQuery? The JavaScript getElementsByName() method can be used to select the required element and this can be passed to a jQuery function to use it further as a jQuery object.
The jQuery syntax is a little simpler, but not much more: $("div") is the jQuery equivalent to document. getElementsByTagName("div") . Here is the API documentation on jQuery's element selector: “Description: Selects all elements with the given tag name.
The :first selector selects the first element. Note: This selector can only select one single element. Use the :first-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the first element in a group (like in the example above).
Beware of spaces :)
And you should quote the value with "
or '
.
$('table[style*="width: 555px"]').css("width", "610px");
If it does not work in IE, you could try to remove the space? (totally untested!)
$('table[style*="width: 555px"],table[style*="width:555px"]')
.css("width", "610px");
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