Panos
asked on
Jquery-Javascript setAttribute function help
Hello experts.
I need to add pseudo attribute to a list element using the following code:
list_item.setAttribute is not a function
Any help to solve this?
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>
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?
ASKER
Hi.
Thank you for your response.
I m using the fineuploader plugin and this is a part of auto generated code.
Thank you for your response.
I m using the fineuploader plugin and this is a part of auto generated code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Julian Hansen
It is working.
Thank you very much
It is working.
Thank you very much
ASKER
Thank you very much.
regards
panos
regards
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);
}
});
You are welcome.
Open in new window
Here's how you interact with the data attributes from jQuery:
Open in new window