jeudi 18 février 2016

Using jQuery to detect if element has a certain style attribute

I'm writing a script to detect whether or not an image is present on a webpage. It's a standard formatting with their html for this section. If there is not an image it looks like

    <div id="photo" style="display: none;">
       <img id="image" src="IMAGESOURCE" onerror="img2txt()" alt="">
    </div>    

if there is an image present that same html looks like this

    <div id="photo">
       <img id="image" src="IMAGESOURCE" onerror="img2txt()" alt="">
    </div>

Right now in the script I'm using this, which doesn't work (or i wouldn't be here :D )

  var images = ($('#photo[style*="display: none"]').length === 0 ? false : true);

    if (images) {
      $('#yes[value="Yes"]').click();
    }
    else {
      $('#no[value="No"]').click();
    }

(The clicks are for the radio buttons on the form that I am filling out based on this image query)

As of right now the if/else statement is giving the radio "No" a click on a page where it should be a yes. I've tried using

    if (!images) {
      $('#yes[value="Yes"]').click();
    }
    else {
      $('#no[value="No"]').click();
    }

just to see if my boolean was incorrect. But with that adjustment it just does the opposite again. Any help is much appreciated. Thanks

Aucun commentaire:

Enregistrer un commentaire