0

I have a div where I want to replace a value of a parameter within an array.

My php code to generate the html is the following

<div id="data1<?php echo $data['id']; ?>" data-url="<?php echo 'post/comment', 
      array('post_id' => $data['id'], 'comment_id' => $data['c_id'])); ?>"></div>

when page is rendered data-url contains

/blog/index.php/post/updateComment?post_id=16&comment_id=''

I want to put a value in comment_id, something like comment_id=12

I tried first to see if I can get the data-url value

but when I do

$('#data1).map(function(){

          alert(this.data-url);
});

it returns NaN

$('#data1).map(function(){

          alert(this.id);
});

return the id as expected

I'd like to know if there is way to search & replace comment_id='' by comment_id=12

Any help would be appreciate

2 Answers 2

1

You don't need to use .map() in this context since you have selected an id,

Try,

$('#data1').data('url');

Please read here to know more about .data() here.

Sign up to request clarification or add additional context in comments.

Comments

0

do like this:

alert($(this).attr('data-url'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.