views:

15

answers:

2

I need to something like this

if($('#ctl00_lblNoResults').text('Please select')){
$('.otherprop').text('Thanks')
}
else {
$('.otherprop').text('No Thanks')
}

So i have a layer like so

<div id="ctl00_lblNoResults">Don't select</div>

And another bit of text

<div class="otherprop">No Thanks</div>

I need to change the text of "otherprop" if "ctl00_lblNoResults" equals this

<div id="ctl00_lblNoResults">Please select</div>

to

<div class="otherprop">Thanks</div>

So desired results are

<div id="ctl00_lblNoResults">Don't select</div>
<div class="otherprop">No Thanks</div>

or

<div id="ctl00_lblNoResults">Please select</div>
<div class="otherprop">Thanks</div>

Hope this makes sense

Thanks

Jamie

+1  A: 
if($('#ctl00_lblNoResults').text() == 'Please select')
$('.otherprop').text('Thanks')
}
else {
$('.otherprop').text('No Thanks')
}

should do it

the if-rule you stated sets the text already, after which it will return true if it was successful (probably false if the id doesn't exist)

Litso
Thanks that works perfectly
Jamie Taylor
A: 

First, what you have should work. All you could do is maybe use a conditional statement when setting .text() to keep it pretty clean (to me, do what's best for your maintaining it of course), like this:

$('.otherprop').text(
  $('#ctl00_lblNoResults').text() == 'Please select' ? 'Thanks' : 'No Thanks';
);
Nick Craver
So unfair, hardcore users always beat me by giving a better answer :P
Litso
@Litso - *Anyone* can give "better" answers than anyone else (though that's subjective in and of itself), as long as they put in the effort :) I've been outdone by very low rep users many, *many* times, lots of tremendously intelligent people here, and rep isn't an indication of that, just your site participation thus far :)
Nick Craver
I know i know, just kidding.
Litso
@Litso - I just don't want to see newer or less active users discouraged is all, *most* of the people posting, new or not provide great content, don't want to see that stop or slow down any :)
Nick Craver
it only encourages me to give more answers, read more better answers, and become smarter overall. don't worry :P
Litso