Jump to content

Recommended Posts

It seems all my items in 'titlesArray' are all at 0 index

 

$('.main ul li h3').each(function(){

var titles = $(this); 
var titlesArray = jQuery.makeArray(titles);

$.each(titlesArray, function(index, value){
document.write(index);

});

});

 

document.write(index); outputs "00000"

 

There are 5 objects within that array, here is the html code

<ul> 
<li>
<h3>Viral Advert</h3>
</li>
<li>
<h3>bannar</h3>
</li>
<li>
<h3>movie</h3>
</li>
<li>
<h3>photo</h3>
</li>
<li>
<h3>movie</h3>
</li>
</ul>

 

Shouldn't my array indexes be 1,2,3,4,5?

Link to comment
https://forums.phpfreaks.com/topic/265128-my-jquery-array-items-only-index-0/
Share on other sites

I want to check for a duplicate of a value

 

$('.main ul li h3').each(function(){

var titles = $(this); 
var titlesArray = jQuery.makeArray(titles);

jQuery.each(titlesArray, function(index, value){

	if (jQuery.inArray(value, titlesArray)){
	      
	}

});

});

 

Then to hide, not remove, the 2nd or more list item that has the duplicate.

Did you copy it exactly as is? Because it's impossible that it is hiding any of the li tags.

 

Anyways, I forgot one of the changes:

 

var foundValues = [];

$('.main ul li h3').each(function()
{
  if($.inArray($(this).text(), foundValues) !== -1)
  {
    $(this).parent().hide();
  }
  else
  {
    foundValues.push($(this).text());
  }
});

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.