2 Replies - 633 Views - Last Post: 07 June 2012 - 12:01 AM

#1 i.rijad  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 06-June 12

question jQuery data attribute selector problem

Posted 06 June 2012 - 04:01 AM

HI
I am trying to acces object which is identified by atribute "data-link"
when i try to run $(".folder"); command i get result

<span class=​"folder" data-link=​"slike\male" data-filter=​"true" data-inline=​"true">​ male​</span>​
<span class=​"folder" data-link=​"slike\male\sdasafa" data-filter=​"true" data-inline=​"true">​ sdasafa​</span>​
<span class=​"folder" data-link=​"slike\original" data-filter=​"true" data-inline=​"true">​ original​</span>​
<span class=​"folder" data-link=​"slike\original\novi" data-filter=​"true" data-inline=​"true">​ novi​</span>​
<span class=​"folder" data-link=​"slike\original\novi\josnoviji" data-filter=​"true" data-inline=​"true">​ josnoviji​</span>​
<span class=​"folder" data-link=​"slike\original\novi\josnoviji\012" data-filter=​"true" data-inline=​"true">​ 012​</span>​



but next commands give me empty object []

$(".folder[link='slike\male']");
$('.folder[link="slike\male"]');
$(".folder:data('link=slike/male')");

please help me to get any of elements idetified by data-link

THNX!

Is This A Good Question/Topic? 0
  • +

Replies To: question jQuery data attribute selector problem

#2 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: question jQuery data attribute selector problem

Posted 06 June 2012 - 11:45 PM

I think your syntax is off a little bit, and you definitely need to escape backslashes. Try this:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<span class="folder" data-link="slike\male" data-filter="true" data-inline="true"> male</span>
<span class="folder" data-link="slike\male\sdasafa" data-filter="true" data-inline="true"> sdasafa</span>
<span class="folder" data-link="slike\original" data-filter="true" data-inline="true"> original</span>
<span class="folder" data-link="slike\original\novi" data-filter="true" data-inline="true"> novi</span>
<span class="folder" data-link="slike\original\novi\josnoviji" data-filter="true" data-inline="true"> josnoviji</span>
<span class="folder" data-link="slike\original\novi\josnoviji\012" data-filter="true" data-inline="true"> 012</span>

<script type="text/javascript">
$('[data-link]').each(function() {
	if($(this).attr('data-link') == 'slike\\male')
	{
		$(this).css({'background-color': '#ff0000'})
	}
});
</script>


There's probably a better way to go about it, but that works in any case.
Was This Post Helpful? 1
  • +
  • -

#3 i.rijad  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 06-June 12

Re: question jQuery data attribute selector problem

Posted 07 June 2012 - 12:01 AM

Thanks for response.. i solved it on similar way
var ovo;
$(".folder").each(function(){if($(this).data('link')==element) ovo=$(this) });


i put object in "ovo" variable
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1