javascriptjqueryhtmlsugarcrmsuitecrm

get content of some tags inside a variable


var a = $('#txta').val();
console.log(a);  

result is complete html code from this url

Now I want to get content of all #artikal-naziv tags (there are 96)

var b = a.find("#artikal-naziv").text();
console.log(b);

Result:

Uncaught TypeError: a.find is not a function

Any help?


Solution

  • .val() takes out the value from the element....Whereas all DOM operations are done on the element... because function like .find() , .hide() , .show() , .closest() etc are used with the element not the value

    The Following modifications should work...

    var a = $('#txta'); // $("#ID") returns the element
    console.log(a.val()); // $("#ID").val() returns the value
    

    the result is complete html code from this URL

    Now I want to get content of all #artikal-naziv tags (there are 96)

    var b = a.find("#artikal-naziv").text(); // .find() easily works on element
    console.log(b);