Alternative to "this" variable
<p>I am trying to write a simple script in JavaScript, just for testing purposes.  I am defining 2 variables, sort of unnecessary, but nice anyway which hold string values for two different scenarios, if the element before the button contains bold text when the button is clicked, the respective variable will be displayed in an alert dialog box.</p>

<p>So, here is my code:</p>

<pre><code>$(document).ready(function(){

  var Bold="Yes, some of this text is bold!";
  var NoBold="No, none of this text is bold.";

  $("&lt;input class="BoldButton" type="button" value="Bold?" id="IntroButton"&gt;&lt;/input&gt;")
  .insertAfter("#intro");

  $("&lt;input class="BoldButton" type="button" value="Bold?" id="LatestNewsButton"&gt;&lt;/input&gt;")
  .insertAfter("#news h2");

  $("input.BoldButton").click(function(){
    if () {
      $('').();
    } else {
        $('').();
      {
});

});
</code></pre>

<p>I was in the middle of writing my if else statement when I realized I do not know how to check if bold is in the element above the button.  I was thinking of using the pseudo-variable this, but I'm pretty sure that's wrong, because wouldn't it be the element before the "this" pseudo-variable?  I think I may be confusing the purpose of this, sorry about that.</p>

<p>Anyway, I really just need a method of checking to see if the element before the button contains bold text, and then I can do the rest. :)</p>

<p>Thanks!</p>

<p>FINAL CODE:</p>

<pre><code>$(document).ready(function(){

  var Bold="Yes, some of this text is bold!";
  var NoBold="No, none of this text is bold.";

  $('&lt;input class="BoldButton" type="button" value="Bold?" id="IntroButton"&gt;')
  .insertAfter("#intro");

  $('&lt;input class="BoldButton" type="button" value="Bold?" id="LatestNewsButton"&gt;')
  .insertAfter("#news p");

 $("input.BoldButton").click(function(){
    if ($(this).prev().is(':has(b, strong)')) {
      alert(Bold);
    } else {
      alert(NoBold);
    }
});

});
</code></pre>
