JavaScript Changing text after a span changing text after effects,changing text color after effects,changing

You can change the price using lastChild and nodeValue like following.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="price">
    <span>$</span>
    10.00
</div>

<script>
    var price = $('#price')[0];
    price.lastChild.nodeValue = "155.00";
</script>
Answer:1

Yes you can do it as:

$("#price").contents(":not(span)").text("Text");
Answer:2

Just add another span to wrap around the price value.

<div id="price">
    <span>$</span>
    <span id="price-value">10.00</span>
</div>

Then you can $("#price-value") to manipulate that part on its own.

Answer:3

As a much easier alternative, one might also use CSS to prepend the currency symbol. This avoids using the span altogether and allows changing the currency symbol.

CSS Examples:

.currency div::before {  content: "$" }
.currency.yen div::before { content: "¥" }

And a working code snippet:

$('#item1').html('10.00');

$('#item2').html('8.80'); 
                       
$('#item3').html( '20.30');
.currency.dollar div::before {  content: "$" }
.currency.pound div::before {  content: "£" }

.currency {
  font-family: monospace;
  font-size: 24px;
  font-weight: bold;
  border: 1px lightgray solid;
  width: 8em;
  padding: 4px;
  text-align: right;
  background-color: ghostwhite;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div class="currency dollar">

  <div id="item1"></div>

  <div id="item2"></div>

  <div id="item3"></div>

</div>
Answer:4

try this

$("#pri").text("100");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="price">
    <span id='si'>$</span>
    <span id='pri'>10.00</span>
</div>
Answer:5

One another way

<script src="http://code.jquery.com/jquery.min.js"></script>
<div id="price">
    <span>$</span>
    10.00
</div>
<script type="text/javascript">
$('#price').contents().last()[0].textContent=' 20.00';
</script>
Answer:6

Setting the text need some old fashioned JavaScript assistance. Using textContent.

$('#price').contents().filter(function() {
    return this.nodeType == 3;
}).last()[0].textContent = 'changed';
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div id="price">
  <span>$</span>
  10.00
</div>
Answer:7

I have a form with URL: localhost:83/mysite/item/UpdateItems/225 I have a temporary table in which I have loaded data and display in my form from temporary table. When I refresh the page I don't ...

I have a form with URL: localhost:83/mysite/item/UpdateItems/225 I have a temporary table in which I have loaded data and display in my form from temporary table. When I refresh the page I don't ...

  1. match string with regex
  2. match string with spaces regex
  3. match string with regex python
  4. match string with regex javascript
  5. match string with regex java
  6. match string with enum java
  7. match string with regex c#
  8. match string with enum c#
  9. match string with regex online
  10. match string with regex in js
  11. match string with regular expression in java
  12. match string with array javascript
  13. match string with pattern in java
  14. match string with regular expression in javascript
  15. match string with special characters regex
  16. match string with number regex
  17. match string with array php
  18. match string with regex ruby
  19. match string with regex php
  20. regex match string

Here is the object I want to re-create dynamically var myPath = { one: [ new google.maps.LatLng(1,2), new google.maps.LatLng(3,4)) ]}; Here is my try without success: var ...

Here is the object I want to re-create dynamically var myPath = { one: [ new google.maps.LatLng(1,2), new google.maps.LatLng(3,4)) ]}; Here is my try without success: var ...

I'm working on a simple script for my site to upload images. I have a multiple file input <input type = 'file' name = 'files[]' id = 'hiddenFile' multiple> that is being triggered by a div click....

I'm working on a simple script for my site to upload images. I have a multiple file input <input type = 'file' name = 'files[]' id = 'hiddenFile' multiple> that is being triggered by a div click....

  1. javascript filereader file name
  2. javascript filereader get name
  3. javascript filereader get file name

I am working on some pretty old code and in every jsp file where there is a javaScript block I see some bizarre Syntax. It goes like : <script language="JavaScript"> <!-- here is the ...

I am working on some pretty old code and in every jsp file where there is a javaScript block I see some bizarre Syntax. It goes like : <script language="JavaScript"> <!-- here is the ...