Weakman10122 Weakman10122 - 1 year ago 52
HTML Question

Javascript/JQuery: How do I select the link inside a <td> element when it has a certain style

There is a website with multiple td elements. I need to a way to click on all the href links inside the td element if it matches a certain style.

Here is what the td element typically looks like

<td style="font-size: 12px; text-align: center; font-weight: bold;"><a class="theclass" href="https://youtube.com" target="_blank">Link</a></td>

Can someone please help guide me on how to do this properly? I tried an if statement to see if the td style matches
"font-size: 12px; text-align: center; font-weight: bold;"
, but it didn't work at all.

Edit: This isn't my website. Sorry, I didn't include this.

Answer Source

It sounds like you are going to have to do a Javascript loop.

 function clickCertainStyles() {
   $('td').each(function(i, td) {
     var $td = $(td);
     if ($td.css('font-size') == '12px' && $td.css('text-align') == 'center')

You can make it faster if you pass in a table container, so you aren't searching the whole page for every TD reference.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download