Title: How is this code working?
Last modified: August 21, 2016

---

# How is this code working?

 *  Resolved [start1988](https://wordpress.org/support/users/start1988/)
 * (@start1988)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-is-this-code-working/)
 * Hi,
 * I am fairly new to WordPress and recently got a project handed down to me to 
   modify. There is something in the code which I can’t figure out how it’s working.
 * Normally in PHP, you use variables to show value. The below code does not have
   any variable or hardcoded value. However when I load the code, there is a value(
   some dollar value) shown where the fullstop is in the code. However, in this 
   code there is only a <span> wrapped around <td>, with both of them having class
   reference to ‘total’. I found nothing special about other parts of this code,
   and there is no reference to the word ‘total’ anywhere in the whole site’s code(
   I checked using windows grep).
 * `<tr>
    <td class=”total”>Total</td> <td class=”total money”><span class=”total”
   >.</span></td> </tr>
 *  I asked around and someone suggested it must be doing it via ajax or javascript.
   But if that’s the case, wouldn’t they still need to have the word ‘total’ in 
   their code somewhere? I never encountered something like this outside of wordpress,
   so I was wondering if someone could suggest how this could be working.
 * Thank you

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-is-this-code-working/#post-4817202)
 * It might normally have total in it, but since the class of total is on a whole
   lot more elements, I’d doubt it in this case. If it was, you’re right that using
   jQuery (which is what’s built into WordPress) the selector is `jQuery ('.total')`.
 * BUT… That doesn’t rule out the possiblity that it’s targeting another element
   and searching for something inside it. In this case it could be something like`
   jQuery ('.money span')` and that would still get the same element, but it will
   find it in a different way.
 * Unfortunately Javascript is a whole lot more messy to debug then PHP is, so it
   will probably take a fair bit more time. I’d suggest using something like Firebug
   if you don’t already so you can see what the scripts are doing.
 *  [Adrian Houle](https://wordpress.org/support/users/adrian-houle/)
 * (@adrian-houle)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-is-this-code-working/#post-4817203)
 * Well what you have shown is just some html, so if the period has been replaced
   in the browser with some value, then yes most likely a script is using the html
   class names as hooks to replace it with its own data.
 * Not really sure how you are viewing this, is it just a tabled in a browser? If
   so you should be able to use a devloper tool to inspect the inserted element 
   and see the script file were it came from.
 *  Thread Starter [start1988](https://wordpress.org/support/users/start1988/)
 * (@start1988)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-is-this-code-working/#post-4817223)
 *  Thread Starter [start1988](https://wordpress.org/support/users/start1988/)
 * (@start1988)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-is-this-code-working/#post-4817224)
 * Thank you for the responses. Turns out like both of you suggested, it was a js
   file that contained code that were using html class as hooks, replacing the values.
 * For those who want to see what it looks like, here it is:
 *     ```
       var $mLevel = $('.membership-level');
       	$mLevel.find('select').change(function() {
       		if($('#new_member_2:checked').length > 0) {
       			var $opt = $(this).find(':selected');
       			$('.payment').toggle($opt.attr('showpayment') == 'true');
       		}
   
       		var $opt = $($mLevel.find('option:selected'));
   
       		var cost = parseFloat($opt.attr('costexgst'));
       		var gst = cost * 0.1;
   
       		$mLevel.find('table.amounts').toggle(cost > 0);
   
       		$mLevel.find('span.membershipLevelName').text($opt.attr('membershiplevel'));
       		$mLevel.find('span.annualFee').text('$ ' + cost.formatMoney(2, '.', ','));
       		$mLevel.find('span.gst').text('$ ' + gst.formatMoney(2, '.', ','));
       		$mLevel.find('span.total').text('$ ' + (gst + cost).formatMoney(2, '.', ','));
       	}).change();
       ```
   
 * The second to last line contains the code that targets span with total class 
   and replace it with a total dollar value.
 * Thank you

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How is this code working?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [start1988](https://wordpress.org/support/users/start1988/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/how-is-this-code-working/#post-4817224)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
