Jump to content

I Can't Seem To Grab A Parent Properly


deadlyp99

Recommended Posts

Hello, i've been working on a site, and there is a specific element I wish to edit.

The trouble I have is there are many instances of the class, so I've been using .parent() in jquery, and I feel I am just doing it wrong.

 

The markup looks like this

 

<div class="disignBoxFirst bx-def-margin-top bx-def-border">
   <div class="boxFirstHeader bx-def-bh-margin">
       <div class="dbTitle">Ad_Rotator</div>
       <div class="clear_both"></div>
   </div>
   <div class="boxContent">
       <div class="dbContentHtml">
           <p id="motivationals"></p>
           <script type="text/javascript">// <![CDATA[ /**buildAdRotator();**/ // ]]></script>
       </div>
   </div>
</div>

 

I am trying to edit the innerHTML of dbTitle.

The div is the first instance of the class on the site, but I don't want code to break if I place new ones before it in the future.

So I wish to use the motivationals id as a handle or reference point since there will only be one instance of that.

 

I've tried

$('#motivationals').parent().parent().parent().first('.dbTitle').html('aasdf');

 

This doesn't behave as I want it to, and I really feel i'm using bad code just looking at that.

Due to the nature of the script I am working on, editing the markup isn't really an option outside of the dbContentHtml div.

 

Any insight on how to properly hop up to the parent, and then down to dbTitle would be much appreciated.

Edited by deadlyp99
Link to comment
Share on other sites

The dbTitle class holds the value of the div's title in the database. That title is used to manage the div's content in the CMS. I could have bypassed all of this by not naming it. But then in the future I could have many divs with no names, which makes determining what's what messy.

But any divs created through the cms get that class to conform to the site's template.

 

Adding an id to it would require me to recode the cms to allow me to add a unique id. Ideally that is what I would want right, but I'm not familiar enough with the very large script to properly do it in a timely manner... It requires restructuring the database, updating all the divs that don't have id's, updating all the backend php for add, editing, and removing said content, as well as possibly needing to modify code that needs to interact with the structure or content of the div's. So I can do that, or throw a simple edit and put the long and hard on my to-do list.

 

I had been throwing various functions at jQuery because I don't know it 100% yet. Thanks for helping out, I have gotten this working, and I got the parent function working ... more cleanly.

 

It appears this will do what I want it to and I don't foresee problems with it so far.

 

$('#motivationals').parents('.disignBoxFirst').find('.dbTitle:first').html('');

 

Thanks a ton.

Edited by deadlyp99
Link to comment
Share on other sites

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.