views:

433

answers:

3

Just trying to replace the hyperlink text and I'm not finding a way to do this... I tried the code below, but, I get a syntax error?

EDIT

<script type="text/javascript">
    var $j = jQuery.noConflict();
    $j(function() {
        if($j("a").text() == "Contact") {
            $j("a").text() = "Connect");
        }
    });
</script>
+2  A: 

You have on bracket to much and the assignment is wrong.

if($j("a").text() == 'Contact') {
   $j("a").text('Connect');
}

instead of

if($j("a").text() == 'Contact')) {
   $j("a").text() == 'Connect');
}

Looks like you just copied and pasted the code from the condition and changed Contact to Connect. Be careful with that.

Felix Kling
Oof, thanks a lot!
phpN00b
+2  A: 
var $j = jQuery.noConflict();
 $j(function() {
  if($j("a").text() == 'Contact') {
   $j("a").text('Connect');
  }

 });

The above fixes your syntax problem, but on the face of it the code only makes sense if there is actually only one link present - $j('a') will select all links in the DOM! What you probably want is:

 $j(function() {
  //Replace hyperlinked 'Contact' texts with 'Connect' text
  $j("a").each(function(){
   if( $j(this).text() == 'Contact' ){
    $j(this).text('Connect');
   }
  });
micahwittman
+1  A: 

You don't assign the text to the method result, you use it as a parameter to the method:

var $j = jQuery.noConflict();

 $j(function() {

  if ($j("a").text() == 'Contact') {
   $j("a").text('Connect');
  }

 });
Guffa