0

Here i have created list using ul tag in jquery code...... I want to get access to those list using class name how can i get it.....

Here is the java script code.... i want to access those list items using class name......

var listItem = "<ul class='list-style' id="+"'"+eId+"'"+" ><li class='list-name'>" + employees[id-1].name + "</li><li class='list-phone-email'>" + employees[id-1].email + "</li><li class='list-phone-email'>+91 " + employees[id-1].mobile + "</ul>";

2
  • Whats the issue? Can you do $('.list-name')? Commented Dec 8, 2016 at 12:35
  • no, i cant get access with that line Commented Dec 8, 2016 at 12:35

3 Answers 3

2

You can create a jQuery object using jQuery(html \[,ownerDocument\]), then use various methods to target elements.

$(listItem).find('.list-name')

var listItem = "<ul class='list-style'><li class='list-name'>Satpal Singh</li><li class='list-phone-email'>Not Required</li></ul>";
console.log($(listItem).find('.list-name').text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

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

Comments

0

i want to access those list items using class name......

 $('ul.list-name');

Get class name from jquery code

 $('ul').attr('class');

To get the contents in the li tags by their class name then

var name = $('li.list-name').text();
var phoneEmail = $('li.list-phone-email').text();

Comments

0

Try this !

$(".list-name").each(function(){ alert($(this).text()); });

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.