Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Wednesday, December 23, 2015

how to get content in a div without specific child element

how to get content in a div without specific child element


i need this content
i dont need this content

I want to get "i need this content" in class .news but without "i dont need this content" in class .summary

$("div.news").not("figure.summary").text()  

I tried this jquery but still gettiing text in figure tag.

Answer by Sharon Haim Pour for how to get content in a div without specific child element


i need this content
i dont need this content

and then:

$(".content").text();  

Answer by Satpal for how to get content in a div without specific child element


You can fetch text nodes using .contents(), then you can .filter() them and perform desired operation.

var text = $('.news').contents().filter(function() {    return this.nodeType == 3;  }).text();    snippet.log(text)
      
i need this content
i dont need this content

Answer by A. Wolff for how to get content in a div without specific child element


alert($("div.news").contents().not("figure.summary").text());
  
i need this content
i dont need this content

You should use contents() to include textNodes:

$("div.news").contents().not("figure.summary").text()  

And if you want to get only textNodes, not filtering out by specific class, type, etc...:

$("div.news").contents().not("div.news *").text()  

Learn more about .contents() at: http://api.jquery.com/contents/

Answer by srivishnu kankipati for how to get content in a div without specific child element


HTMLDivElement HDEMI =(HTMLDivElement)myHTMLDocument.getElementByName("news");  Out_OutputMemberID = Convert.ToString(                        ((mshtml.IHTMLDOMNode)(HDEMI.firstChild).nodevalue);  

Answer by Umakant Ver.a for how to get content in a div without specific child element


You should try this one:

var element = $(".news");  element = element.children().remove();  var text = element.html();  

First take parent element in a variable:

var element = $(".news");  

Remove children form parent:

element = element.children().remove();  

Now read form parent:

var text = element.html();  


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.