Deepika
Deepika

Reputation: 826

How to change date-value?

I have a following HTML but I am not able to change the value of date-value and title. Can you please suggest how to do this?

<a title="Date::04/08/2013">
  <span class="name">Date::</span>
  <span data-value="04/08/2013" class="value">04/16/2013</span>
</a>

Sorry for the incomplete question.

Value 04/16/2013 is assigned using jQuery but the title="Date::04/08/2013" and data-value="04/08/2013" doesn't changed. I want "Date::04/08/2013" should be "Date::04/16/2013" and data-value="04/08/2013" should be data-value="04/16/2013".

Thanks in advance.

Upvotes: 0

Views: 141

Answers (5)

Salil
Salil

Reputation: 47482

I think you have this

<a title="Date::04/08/2013" id='date-link'>
  <span id="date-title" class="name">Date::</span>
  <span id="date-value" data-value="04/08/2013" class="value">04/16/2013</span>
</a>

and you want following

<a title="Date::04/16/2013" id='date-link'>
  <span id="date-title" class="name">Date::</span>
  <span id="date-value" data-value="04/16/2013" class="value">04/16/2013</span>
</a>

If so, you can try following

var dateTitle = jQuery("#date-title").html()
var dateValue = jQuery("#date-value").html()
jQuery('#date-link').attr('title', dateTitle+dateValue);
jQuery('#date-value').attr('data-value', dateValue);

You can create a html file with following code and check your own

<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>

<a title="Date::04/08/2013" id='date-link'>
  <span id="date-title" class="name">Date::</span>
  <span id="date-value" data-value="04/08/2013" class="value">04/16/2013</span>
</a>

<a href ="javascript:void(0)" onclick="abc()">Click Here</a>

<script>
    function abc() {
    var dateTitle = jQuery("#date-title").html()
    var dateValue = jQuery("#date-value").html()
    jQuery('#date-link').attr('title', dateTitle+dateValue);
    jQuery('#date-value').attr('data-value', dateValue);}
</script>

Upvotes: 1

vinothini
vinothini

Reputation: 2604

var value = $('.value').text();
$('.value').attr('data-value',value)

Upvotes: 0

eurica
eurica

Reputation: 120

$('.value').attr('data-value',$('.value').html());

Upvotes: 0

tamilmani
tamilmani

Reputation: 591

html code:

<a title="Date" id="data">
  <span class="name">Date::</span>
  <span data-value="04/08/2013" class="value">04/16/2013</span>
</a>

js:

$("#data").find('span').attr("data-value", "04/16/2013");

try this u ll get data-value...

Upvotes: 0

loxxy
loxxy

Reputation: 13151

Try this :

$('span.value').attr("data-value", "04/16/2013")

.data("value") might not work, since value maps to something else.

Besides, try using some other keyword other than value, if possible.

Upvotes: 0

Related Questions