2

I have created a chrome extension that successfully creates a popup with a basic test if else statement. I would like to have the if statement be (if: the current active page contains "a certain string of html code (or image name)" than popup message is displayed)

I have tested multiple jquery if else statements about reading html elements but none seemed to work

The code below works changing the variable back and forth to display the correct alert. However, I would like to make the if statement to be searching the current page for a certain checkbox that is within a unique div and has an image that is either img_checked or img_unchecked. If the image is checked i want the if statement to return true, and if not return false

    popup.js

    var a = 1;
    if (a == 0){
    alert("True");
    }
    else {
    alert("false");
    }`

code currently works but If i try to try adding an if statement that scans the page for the set of html i want, the page alert doesnt show at all.

I tried this code and had no alert come back:

    val $nav = jQuery('id="img_chkbox" title="Checked"');
    if( $nav.length > 0 && $nav.is(':visible')==true){
    alert("true");
    }else {
    alert("false");
    }
Jonathan
  • 21
  • 2
  • You need to provide your code attempts that did not work. Otherwise there is no way for us to point out the issues you encountered. – Taplar May 30 '19 at 17:34
  • Possible duplicate of [How to access the webpage DOM rather than the extension page DOM?](https://stackoverflow.com/questions/4532236/how-to-access-the-webpage-dom-rather-than-the-extension-page-dom) – wOxxOm May 30 '19 at 17:35
  • @Taplar Im just looking for a place to start with an if else statement that works the way I specified and as a chrome extension. I havent ever made a chrome extension or worked much with jquery. Sorry, I just have so little experience with this specific thing I dont know what is close to working and what is completely wrong. – Jonathan May 30 '19 at 17:52
  • If you have a problem with creating logic, you need to ask about the issues you are having. Simply asking for someone else to do it entirely for you is off topic as you are making a coding request. We're here to help you understand your issues, not write code for you – Taplar May 30 '19 at 17:53
  • @Taplar I updated my post with a statement I tried based off another post. Doesnt make an alert at all now. Im not wanting you to write the whole code for me, I have everything working except the if else statement. – Jonathan May 30 '19 at 17:57
  • Well, that's an invalid selector. `jQuery('#00N34000005RPOC_chkbox[title="Checked"]')` – Taplar May 30 '19 at 17:58
  • Like I said, I know too little about the syntax of this so I cant pinpoint what looks wrong or doesn't make sense. If I could, I wouldn't be asking for help. – Jonathan May 30 '19 at 18:01
  • Can you give a suggestion on a way to properly use a selector to identify if the page contains a string of specified HTML or something that may work similarly? – Jonathan May 30 '19 at 18:03

0 Answers0