title: Use JavaScript with UIWebView to retrieve element by ID- SWIFT
body: <p>I am using a <code>UIWebView</code> to load a webpage that is an article. Once I press a button, I create a struct with the <code>url</code>, <code>title</code>, and <code>image</code>. To access the title, I need to access the webpage's source code and grab the title from a <code>h1 header</code> that has the same class ID (class="c-page-title") for every article. Would anyone know how to use the <code>stringByEvaluatingJavaScript</code> or <code>evaluateJavaScript</code> function to get the text from the <code>h1 header</code>?</p>
  
  <p>Here is some of my code for reference:</p>
  
  <p>Struct:</p>
  
  <pre><code>struct Article {
  
      var url: URL
      var img: URL
      var title: String
  
      init(url: URL, img: URL, title: String) {
          self.url = url
          self.img = img
          self.title = title
      }
  }
  </code></pre>
  
  <p>Function that fills the Article struct:</p>
  
  <pre><code>    @IBAction func bookmarkArt(_ sender: Any) {
  
      let articleInst = Article(url: (mainWebView.request?.url)!, img: (mainWebView.request?.url)!, title: "Article Here")
      bookmarks.append(articleInst)
      print("array: \(bookmarks)")
  
      let alertController = UIAlertController(title: "Bookmark added!", message: "This article was just added to your bookmarks.", preferredStyle: UIAlertControllerStyle.alert)
  
      // Replace UIAlertActionStyle.Default by UIAlertActionStyle.default
      let okAction = UIAlertAction(title: "Awesome, thanks!", style: UIAlertActionStyle.default) {
          (result : UIAlertAction) -&gt; Void in
          print("OK")
      }
  
      alertController.addAction(okAction)
      self.present(alertController, animated: true, completion: nil)
  }
  </code></pre>
  
  <p>Any help would be immensely appreciated!! Thanks so much in advance.</p>
  
  <p>Cheers,
  Theo</p>