Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

Jquery-Javascript setAttribute function help

Hello experts.
I need to add pseudo attribute to a list element using the following code:
<ul id="itemimagegallery">
  <li class="qq-file-id-0" qq-file-id="0">
  </li>
  <li class="qq-file-id-1" qq-file-id="1">
  </li>
</ul>
 <script type="text/javascript">
$(function() {
	var uu = 'uzuiuz-hkjhkj-ujhkjk';
	var tid = 0;
	var list_item = $('#itemimagegallery').find('.qq-file-id-' + tid);
	if(list_item.length){
		list_item.setAttribute("qq-file-uuid", uu);
	}
});
	</script>

Open in new window

I m using jquery-1.11.3.min.js and the error i get:
list_item.setAttribute is not a function

Any help to solve this?
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

You should be using data attributes for this.
<li class="qq-file-id-0" data-file-id="0">

Open in new window


Here's how you interact with the data attributes from jQuery:

var fileId = $('#itemimagegallery').data('file-id'); //getter

$('#itemimagegallery').data('file-id',2); //setter

Open in new window

Avatar of Panos

ASKER

Hi.
Thank you for your response.
I m using the fineuploader plugin and this is a part of auto generated code.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi Julian Hansen
It is working.
Thank you very much
Avatar of Panos

ASKER

Thank you very much.
regards
panos
Avatar of Panos

ASKER

A little remake:
<ul id="itemimagegallery">
  <li class="qq-file-id-0" qq-file-id="0">
  </li>
  <li class="qq-file-id-1" qq-file-id="1">
  </li>
</ul>
$(function() {
	var uu = 'uzuiuz-hkjhkj-ujhkjk';
	var tid = 1;
	var list_item = $("#itemimagegallery").find("[qq-file-id='" + tid + "']");
	if(list_item.length){
		list_item.attr('qq-file-uuid',uu);
	}
});

Open in new window

You are welcome.